Search code examples
oauth-2.0oauthazure-active-directorymicrosoft-graph-api

Alternative to OAuth 2.0 ROPC without interpreting HTML/Javascript


I'm in the context of an embedded devices that uses an HTTPS client to request an access token on behalf of a user (delegated permission needed for the app).

I'm currently using OAuth 2.0 ROPC (https://learn.microsoft.com/en-us/azure/active-directory/develop/v2-oauth-ropc) to get my token and everything works fine.

But since this authentication is deprecated I'd like to change to a more secure solution that works in hybrid identity federation scenarios.

I see that many other solutions exists, but I can't find one that doesn't need to interpret an HTML/JS response.

Here a CURL example to explain my point:

ROPC request:

curl -X POST "https://login.microsoftonline.com/<tenant_id>/oauth2/v2.0/token" --data "grant_type=password&scope=EWS.AccessAsUser.All&username=<username>&password=<password>&client_id=<client_id>&client_secret=<client_secret>" -H "Content-Type: application/x-www-form-urlencoded"

Response: {"token_type":"Bearer","expires_in":3599,"ext_expires_in":3599,"access_token":"eyJ0eX....1234"}

Here I can extract the token directly from the response.

But using other ways to get delegated permission token such as OAuth 2.0 Implicit Grant flow (https://learn.microsoft.com/en-us/azure/active-directory/develop/v2-oauth2-implicit-grant-flow), responses are always an HTML that I can't interpret.

So here I am wondering if there is a solution to this situation.

Thanks in advance, Aloïs KYROU


Solution

  • You cannot use the implicit flow to obtain the token in the tool, you can only run the request url in the browser. Because using the implicit flow requires you to log in. Please note that before this, you must enable id token and access token.

    enter image description here

    Request the id token and access token in the browser.

    https://login.microsoftonline.com/{tenant id}/oauth2/v2.0/authorize?
    client_id={client id}
    &response_type=id_token token
    &redirect_uri={redirect_uri}
    &scope=openid EWS.AccessAsUser.All
    &response_mode=fragment
    &state=12345
    &nonce=678910