Microsoft Graph - How to obtain token non-interactively?

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP



Microsoft Graph - How to obtain token non-interactively?



I want to obtain a token on Microsoft Graph via a GET request.
If I use the following call, I get a login screen asking for username and password.


https://login.microsoftonline.com/common/oauth2/v2.0/authorize?
client_id=f3992025-4d4d-XXXXX-bb2d-XXXXXXXXX
&client_secret=XXXXXXXXXXXXXXXXXXXXXXXXXX
&response_type=code
&redirect_uri=https://10.100.XXX.XXX:5858/authorize
&response_mode=query
&scope=openid%20offline_access%20https%3A%2F%2Fgraph.microsoft.com%2Fmail.read
&state=12345



if I do so, i do I get the code necessary to later obtain the token and I can use it no without issues



My problem is that I don't want to that login screen. I want the request to return the code without user interaction. I thought that the client_id and client_secret would take care of this.



I am following this directions: https://developer.microsoft.com/en-us/graph/docs/concepts/auth_overview



Thank you.





What you are looking for is Client Credentials Grant flow I think :) It involves no browser, just a single HTTP request. It does rely on Application Permissions, permissions granted to your app itself, no on behalf of users.
– juunas
Aug 7 at 19:11





Thanks! I added &grant_type=client_credentials when I perform a request to /authorize however I still get an interactive login screen.
– acanessa
Aug 7 at 20:28





@acanessa Did you tried in Postman or any client tool?
– Jayendran
Aug 8 at 4:53




1 Answer
1



As far as I know, you can use OAuth 2.0 client credentials grant to access web-hosted resources by using the identity of an application.It's is used for server-to-server interactions.For more information, please click https://docs.microsoft.com/en-us/azure/active-directory/develop/v2-oauth2-client-creds-grant-flow.


POST https://login.microsoftonline.com/tenant/oauth2/v2.0/token
client_id=f3992025-4d4d-XXXXX-bb2d-XXXXXXXXX
&scope=https://graph.microsoft.com/.default
&client_secret=XXXXXXXXXXXXXXXXXXXXXXXXXX
&grant_type=client_credentials





My issue is resolved. Now i see that i don't need /authorize and i can go straight to /token with this flow. I also had an issue with my code that was returning the response info, and not the body (with the token). Using CURL as mentioned on the link you provided gave me the clue for this. Thanks!
– acanessa
Aug 8 at 14:23






By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Popular posts from this blog

Firebase Auth - with Email and Password - Check user already registered

Dynamically update html content plain JS

How to determine optimal route across keyboard