Hi @Chroafjd ,
Thanks for reaching out.
I understand that you want to call protected Web API from the web Application and trying to get the token using Authorization Code Flow.
The authorization grant flow is used to get the access token to call protected resources Web API mainly from web applications, Single Page applications for signed in user.
In Authorization grant flow, there are two steps involved to get the access token.
- Call authorize endpoint to get the short-lived code through the browser as user sign in is required https://login.microsoftonline.com/{tenant}/oauth2/v2.0/authorize?
As you might noticed in your postman, when you are calling authorize endpoint, you might get successful response but in response it asking to “Sign into your account”.
Also, I noticed the client_id you are passing in the request is not matching with your application id of client application. You need to set all the below parameter correctly to get the authorize code
client_id : application id of client application
response_type : code
redirect_uri : where code need to send. It should match with the redirect URI you mentioned in the portal while registering the application.
Scope : permission API can expose to
Response_mode : how requested token should return
After passing all the parameter correctly, URL need to paste in browser for signed in user to accept the permissions and you will get code in query along with redirect URI you mentioned in the request.
2.Now that you've acquired an authorization_code and have been granted permission by the user. You can call token endpoint to get access token from code https://login.microsoftonline.com/{tenant-id}/oauth2/v2.0/token endpoint.
Here the client_id and client_secret is of your client application which is requesting access token to call protected API.
In the scope, you need to mention the permissions an API can expose to. As mentioned by you, scopes of your web API have been defined which need to add to client application as below:
Client application call APIs on behalf of the signed-in user. To do that, they must request delegated permissions.
Client Application ->API Permissions->Add a permission->My APIs
Hope this will help to get the access token using authorization grant flow. If you have any further question on this, do let me know.
Thanks,
Shweta
--------------------------------
Please remember to "Accept Answer" if answer helped you.