We have application registered in our B2C tenant and we are trying to read user's information after they login in the application using MS Graph SDK.
C#
var me = await graphClient.Me.Request().GetAsync();
Permission
https://graph.microsoft.com/User.Read
We are able to get the access token from login.microsoftonline.com using OAuth 2.0 authorization code flow but not in .b2clogin.com.
Below is the snippet of the code
public async Task<AuthenticationResult> GetUserAccessTokenByAuthorizationCode(string authorizationCode)
{
AuthenticationResult aa;
aa = await _app.AcquireTokenByAuthorizationCode(_scopes, authorizationCode).ExecuteAsync();
return aa;
}
Below is the result when we get the access token with authorization code from B2C authorization endpoint.
Screenshot where access token is NULL
I found this post(I only quoted some of the comments below from the post)
Mass confusion here. You can definitely do what you are looking to do, except that this is all Azure AD functionality, not Azure AD B2C. So you are not looking to invoke any B2C user flow etc. B2C auths cannot get access to Microsoft APIs, only your own APIs.
AAD tenant - contains only AAD endpoints. It is a single token issuer.
B2C tenant - contains both AAD and B2C token endpoints. There are two token issuers respectively
You cannot use tenantName.b2clogin.com to obtain a token for MS Graph API, based on the above rule set. This means a users B2C authentication cannot be used to authorize to AAD protected apps, or Microsoft APIs.
Based on the comments above, Is it really true that we cannot access the MS Graph from B2C application but we can only access when app is registered in AAD?
I am wondering since login.microsoftonline.com is already deprecated and microsoft advise to use b2clogin instead.
Please share your thoughts. Thank you.