manishrasrani / ms-adal-angular6

This is a wrapper library for Angular 6+ (Angular 6.X.X and Angular 7.X.X) modules over Microsoft ADAL (Azure Active Directory Authentication Library)
https://www.npmjs.com/package/microsoft-adal-angular6
MIT License
34 stars 13 forks source link

Can't access my API #9

Closed navi-dev closed 5 years ago

navi-dev commented 5 years ago

I have been trying to integrate the ADon my SPA and API project. I am able to login to the SPA but when it comes to generate the access token and passing to the API it always say unauthorized.

Digging down I found that API says invalid audience. Even I try to decode the token the audience Id is the SPA app id not the API app id.

I am not sure where to change. To generate the access token I have done the following this.adal.acquireToken('app url'). this.adal.acquireToken('localhost api host'). this.adal.acquireToken('oauth token url').

But nothing seems to be working it seems its giving me the same id_token instead of access token.

ramnefalt commented 5 years ago

navi-dev you need to call acquireToken(url) to get your access token. Have you tried that? Or do you have MFA enabled?

manishrasrani commented 5 years ago

nani-dev - looks like your API would need to white-list the audience for which you are generating the token. Also your API must validate the token against the same audience that your client is generating the token for.

sonphnt commented 5 years ago

Hi I have the same issue. I have tried multiple ways in acquireToken(url), But it still return the same access token that I could not pass to API.

I decode the token I get the property "aud" is always Angular ClientId that was supposed to be WebAPI ClientAPI instead.

Does anyone get this done with 2 apps: 1 Angular and 1 Web API ?

Thanks