I have an Angular 6 app where I am authenticating the user using microsoft-adal-angular6 against Azure Active Directory. That is working fine.
I then take the user OID and run:
https://graph.microsoft.com/v1.0/users/' + this.userOID + '/memberOf
To run that call I need to have my applications token and the appropriate permission.
https://login.microsoftonline.com/' + this.appID + '/oauth2/v2.0/token
my code looks like this...
getAuzrdddeToken(): Observable<any> {
const url = 'https://login.microsoftonline.com/'
+ environment.adalConfigGraph.orgID + '/oauth2/v2.0/token';
const headers = new HttpHeaders({'Content-Type': 'application/x-www-form-urlencoded'});
const body = new HttpParams();
body.set('client_id', environment.adalConfigGraph.clientID);
body.set('grant_type', 'client_credentials');
body.set('scope', 'https://graph.microsoft.com/.default');
body.set('client_secret', environment.adalConfigGraph.secret);
return this._http.post(url, body, {headers: headers}).pipe(
tap(data => console.log('======== Token: ' + JSON.stringify(data))),
);
}
I have the permission working fine, and the call itself is working in Postman, but when I try to build this into Angular I am getting the following error.
Access to XMLHttpRequest at 'https://login.microsoftonline.com/xxx/oauth2/v2.0/token' from origin 'http://localhost:4201' has been blocked by CORS policy: Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource.
I'm not a particularly advanced Angular/AAD user, but it seems to me that maybe I am constructing my service wrong or the header or the body of the request?
I am also currently trying to store the token in a string on the class where I get the token, but if someone can help me with the correct way to store that for consumption around the Angular app, that would be appreciated.