Having an issue with Oauth2

Jose David Rojas Aguilar 1 Reputation point
2022-06-07T22:37:59.033+00:00

I configured a node-based oauth2 authentication process using this library: passport-oauth2.

It's working when I log in with a professional account but When I try to log in with an email @harsh.com .com, I get a 403 error when I consume https://graph.microsoft.com/v1.0/me with the token I get from the login flow.

Should I use another endpoint for not-corporate domains like @Karima ben .com or @harsh.com .com?

Microsoft Security | Microsoft Entra | Microsoft Entra ID
{count} votes

2 answers

Sort by: Most helpful
  1. Vicky Kumar (Mindtree Consulting PVT LTD) 1,161 Reputation points Microsoft Employee
    2022-06-08T05:58:50.177+00:00

    Thanks for reaching out to us, could you please put your decode access token http://jwt.ms/ and see if the permission is present or not. User.Read permission is sufficient but could you please try by adding scopes User.ReadAll permission.


  2. Shweta Mathur 30,431 Reputation points Microsoft Employee Moderator
    2022-06-08T06:24:57.1+00:00

    Hi @Jose David Rojas Aguilar ,

    Thanks for reaching out.

    I understand you are trying to access Graph API endpoint with personal accounts and getting "ErrorInsufficientPermissionsInAccessToken" error.

    This could be due to sign-in audience is not correctly configured in "supported account types" while registering the application.

    209366-image1.png

    Selecting the "Accounts in any organizational directory and personal Microsoft accounts" option will allow users who have personal Microsoft accounts and users from another tenant to access the application.

    You need to call common endpoint to authenticate the user which should allow both Microsoft accounts and work or school accounts to access the application

    https://login.microsoftonline.com/common/oauth2/v2.0/token

    Also, make sure if you have registered your application initially as single tenant but wants to allow users from another tenant or Microsoft accounts as well. I would recommend to register the new application with above option to target largest sign-in audience to access your application.

    Updating the account supported by an application will sometimes not allow to update application from single-tenant to multi-tenant due to Application ID URI (App ID URI) name collisions. So it is better to avoid that and register new application as multi-tenant application.

    Hope this will help.

    Thanks,
    Shweta

    -------------------------------------

    Please remember to "Accept Answer" if answer helped you.


Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.