# Can't get Azure AD working with SPA application

**URL:** <https://community.auth0.com/t/cant-get-azure-ad-working-with-spa-application/7230>\
**Category:** Get Help\
**Tags:** application-failure, not-working, azure-ad\
**Created:** [June 23, 2017, 7:52am UTC](https://community.auth0.com/t/cant-get-azure-ad-working-with-spa-application/7230 "2017-06-23T07:52:39Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![nick.savenko](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/nick.savenko/32/5460_2.png) [@nick.savenko](https://community.auth0.com/u/nick.savenko)\
**Post date:** [June 23, 2017, 7:52am UTC](https://community.auth0.com/t/cant-get-azure-ad-working-with-spa-application/7230/1 "2017-06-23T07:52:39Z")

</div>

Hi  
Guys, Auth0 is the most complex thing I have ever used. So many things needs to be discovered… Anyway, am trying to setup an Azure AD multi-tenant app and I can’t get it working. I am sure, I am missing something obvious. I have got everything working when using “Try” button from the Auth0 portal.

```
                var webAuth = new Auth0.WebAuth({
                  domain: AUTH_CONFIG.domain,
                  clientID: AUTH_CONFIG.clientID
                });

                webAuth.authorize({
                    connection: 'digital-dealers-waad',
                    responseType: 'code',
                    redirectUri :AUTH_CONFIG.callbackURL,
                    prompt:"consent",
                });

```

Where call back URL - [http://localhost:4200/callback](http://localhost:4200/callback) - my Angular2 App  
I am getting a code:

```
http://localhost:4200/callback?code=ReJnUpqetKd3HR9S

```

Btu what to do after with that code, I have no idea. I was trying to call Azure AD with that code, but it doesn’t work

```
            // Get the user's profile from Azure AD.
            var credential = new ClientCredential("AppKey",
                "AppSecret");
            var authContext = new AuthenticationContext("https://login.windows.net/common/");

            try
            {
                var result = await authContext.AcquireTokenByAuthorizationCodeAsync("ReJnUpqetKd3HR9S", new Uri("https://digital-dealers.au.auth0.com/login/callback"), credential);
            }catch(Exception ex)
            {
                string s = ex.Message;
            }

            return Ok();

```

But it returns BadRequest saying that Code is invalid.  
Please HELP!!!

---

<div class="post-metadata">

**Author:** ![prashantT](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/prashantt/32/6002_2.png) [@prashantT](https://community.auth0.com/u/prashantT)\
**Post date:** [June 23, 2017, 8:23am UTC](https://community.auth0.com/t/cant-get-azure-ad-working-with-spa-application/7230/2 "2017-06-23T08:23:22Z")

</div>

The `responseType` parameter determines whether Auth0 redirects to your callback/application with an `authorization_code`, or an `id_token`. Because your frontend is a Single Page Application, we recommend using the `responseType: 'token'`, which will redirect to your application with the `id_token` in the URL hash. The [parseHash](https://auth0.com/docs/libraries/auth0js/v8#extract-the-authresult-and-get-user-info) method will parse the hash fragment and extract the authentication result.

---

<div class="post-metadata">

**Author:** ![nick.savenko](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/nick.savenko/32/5460_2.png) [@nick.savenko](https://community.auth0.com/u/nick.savenko)\
**Post date:** [June 23, 2017, 8:37am UTC](https://community.auth0.com/t/cant-get-azure-ad-working-with-spa-application/7230/3 "2017-06-23T08:37:03Z")

</div>

Thank you so much for reply prashant.  
Now I get something like this:  
[http://localhost:4200/callback#access\_token=YyJ1pv\_dAAFHdcPL&expires\_in=86400&token\_type=Bearer&state=Ts~w2OtXPHG-txRx9bXlt3k\_Q5NpsIvF](http://localhost:4200/callback#access_token=YyJ1pv_dAAFHdcPL&expires_in=86400&token_type=Bearer&state=Ts~w2OtXPHG-txRx9bXlt3k_Q5NpsIvF)

What I should do with this token to get user id? Call Azure AD? Auth0 api?

Thanks  
Nick

---

<div class="post-metadata">

**Author:** ![nick.savenko](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/nick.savenko/32/5460_2.png) [@nick.savenko](https://community.auth0.com/u/nick.savenko)\
**Post date:** [June 23, 2017, 8:37am UTC](https://community.auth0.com/t/cant-get-azure-ad-working-with-spa-application/7230/4 "2017-06-23T08:37:03Z")

</div>

Thank you so much for reply prashant.  
Now I get something like this:  
[http://localhost:4200/callback#access\_token=YyJ1pv\_dAAFHdcPL&expires\_in=86400&token\_type=Bearer&state=Ts~w2OtXPHG-txRx9bXlt3k\_Q5NpsIvF](http://localhost:4200/callback#access_token=YyJ1pv_dAAFHdcPL&expires_in=86400&token_type=Bearer&state=Ts~w2OtXPHG-txRx9bXlt3k_Q5NpsIvF)

What I should do with this token to get user id? Call Azure AD? Auth0 api?

Thanks  
Nick

---

<div class="post-metadata">

**Author:** ![system](https://global.discourse-cdn.com/auth0/original/3X/b/5/b560f266932fcce5d57f09a6595bd50518cae3f3.jpeg) [@system](https://community.auth0.com/u/system)\
**Post date:** [March 2, 2018, 5:54am UTC](https://community.auth0.com/t/cant-get-azure-ad-working-with-spa-application/7230/5 "2018-03-02T05:54:54Z")

</div>


