0
votes

I am using Azure AD and have to call an API to get access token to start a pipeline.

I am using OAuth2 for authorization but don't know the right way to do that.

I tried it using Postman and was able to get reponse successfully.

but when I tried the same using Angular n Node.

In Angular I got CORS error and In Node I got a status code of 401 in message

I have endpoint URL which i'm using to get token from Azure AD which i have test on Postman something like this.

https://login.microsoftonline.com/{SomeID}/oauth2/token

request headers:

Content-Type: application/x-www-form-urlencoded

request body:

grant_type: client_credentials

client_id: {Client_ID}

client_secret: {Secret}

resource: https://management.azure.com

For node i used third-party package name AXIOS

I feel it is not right to pass the request from Angular itself so send the request from backend only make sense.

Please Help me I am stuck from 2 weeks reading documentation but not getting anywhere.

A code would be of great help.

1
You can use sdk @azure/msal-angular to implement Azure AD auth. After doing that, you can avoid the CORS issue. For more details about how to implement, please refer to the sample : docs.microsoft.com/en-us/samples/azure-samples/…Jim Xu
@JimXu the example is for login popup i want to do more of a silent authenticationrocky shinde
According to the situation, I think you can make a backend server to request access token and call other api. If you use nodejs to create backend server, you can refer to the sampe to get token :npmjs.com/package/…Jim Xu

1 Answers

0
votes

For your Angular app you should use Authorization Code Flow (PKCE) and use a security library to do the heavy lifting

RESOURCES OF MINE

I have an Azure AD code sample with an SPA and API that you can use to get connected:

Hopefully the blog post at least gives you some ideas of what a solution looks like technically, and you can then adapt it as you see fit.