Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to login with username/password using OAuth2 and microsoft login and HTTP request

How to login with username/password (end-user credentials) using OAuth2 and Microsoft login

https://login.microsoftonline.com/{app-id}/oauth2/token

like image 957
ColacX Avatar asked Dec 14 '22 02:12

ColacX


1 Answers

Microsoft does not recommend passing username/password information for endusers. That is why they dont post guides for this. For security reason they want you to use the redirection to their login page. Use https://login.microsoftonline.com/{tenant-id}/oauth2/authorize to get there.

However it is possible and very easy to do this using their oauth2 rest api.

Create an http request to

base url: https://login.microsoftonline.com/{tenant-id}/oauth2/token
{tenant-id} //obtained from AzureAD config section

Use the following request parameters in the body section

grant_type = password //read up on the other grant types, they are all useful, client_credentials and authorization_code
client_id = {client-id}//obtained from the application section in AzureAD
client_secret = {client-secret}//obtained from the application section in AzureAD
resource = https://graph.microsoft.com //there is also the api https://graph.windows.net, use the latest and best one
username = {enduser-username} //example [email protected]
password = {enduser-password} //example Hs782f8a

A successful response should include the access_token and refresh_token

Tested in year 2016

Recommended links

  • Postman
  • Microsoft Graph
  • Windows Graph
like image 176
ColacX Avatar answered May 24 '23 23:05

ColacX