Answered by:
Unable to use AddSignIn Method of Microsoft.Identity.Web NuGet Package to acquire an AccessToken for Authorization Code Flow

Question
-
We want to use MSAL for Authentication in our Web application with Web API using Authorization Code Flow.
I was using Sample from GitHub (https://github.com/Azure-Samples/active-directory-aspnetcore-webapp-openidconnect-v2/tree/master/4-WebApp-your-API/4-2-B2C). But unfortunately it uses Implicit Code Flow by default.
Note: I disabled both Access Token and Id Token from Implicit Flow option for the application on the Azure Portal.
As I can see in request URL for Authorization EndPoint, the ResponseType was "code id_token". But we just want to use Authorization Code Flow everywhere. So It needs to be "code" only.
Then I found in this StackOverflow Article (https://stackoverflow.com/questions/61554550/azure-ad-b2c-error-aadb2c90057-when-i-am-not-trying-to-use-the-implicit-flow) someone faced the same problem, I commented this line of code in Github sample
//services.AddSignIn(Configuration, "AzureAdB2C");And added block of code from update section in StackOverflow Article (https://stackoverflow.com/questions/61554550/azure-ad-b2c-error-aadb2c90057-when-i-am-not-trying-to-use-the-implicit-flow).
Then I now get the following error:
Microsoft.IdentityModel.Protocols.OpenIdConnect.OpenIdConnectProtocolException: IDX21336: Both 'id_token' and 'access_token' should be present in OpenIdConnectProtocolValidationContext.ProtocolMessage received from Token Endpoint. Cannot process the message.
To fix it, I added "client id" scope to OpenIdConnectOptions according to this article (https://github.com/dotnet/aspnetcore/issues/23284#issuecomment-648775392)
Further, AcquireTokenByAuthorizationCode method was throwing a long exception with top line:
at Microsoft.Identity.Client.OAuth2.OAuth2Client.ThrowServerException(HttpResponse response, RequestContext requestContext)
I changed "Instance" in appsetting from https://company.b2clogin.com to https://company.b2clogin.com/tfp/.
Now I am getting Id Token, but AccessToken is returned null by AcquireTokenByAuthorizationCode method.
Am I still missing some configuration OR its some bug in Microsoft.Identity.Web with Authorization Code Flow?
Is it fine to use AddAuthentication with options for AzureADB2C(MSAL) OR We should be using AddSignIn Method only?
- Moved by Xingyu ZhaoMicrosoft contingent staff Monday, July 13, 2020 1:35 AM
Friday, July 10, 2020 2:05 PM
Answers
-
I'd try asking for help over here.
also note the Azure forums have migrated to QnA
https://docs.microsoft.com/en-us/answers/index.html
here you can Ask a question and assign appropriate tags.
https://docs.microsoft.com/en-us/answers/topics.html?sort=name
Regards, Dave Patrick ....
Microsoft Certified Professional
Microsoft MVP [Windows Server] Datacenter Management
Disclaimer: This posting is provided "AS IS" with no warranties or guarantees, and confers no rights.- Proposed as answer by Guido Franzke Monday, July 13, 2020 8:48 AM
- Marked as answer by Guido Franzke Monday, July 20, 2020 6:50 AM
Monday, July 13, 2020 2:22 AM
All replies
-
Hi Rajeev Singh Chib,
I have moved the thread to 'where is the forum for...?' forum to help you find the correct forum to go ask questions.
Thank you for your understanding.
Best Regards,
Xingyu Zhao
MSDN Community Support
Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.Monday, July 13, 2020 1:34 AM -
I'd try asking for help over here.
also note the Azure forums have migrated to QnA
https://docs.microsoft.com/en-us/answers/index.html
here you can Ask a question and assign appropriate tags.
https://docs.microsoft.com/en-us/answers/topics.html?sort=name
Regards, Dave Patrick ....
Microsoft Certified Professional
Microsoft MVP [Windows Server] Datacenter Management
Disclaimer: This posting is provided "AS IS" with no warranties or guarantees, and confers no rights.- Proposed as answer by Guido Franzke Monday, July 13, 2020 8:48 AM
- Marked as answer by Guido Franzke Monday, July 20, 2020 6:50 AM
Monday, July 13, 2020 2:22 AM -
Thanks Xingyu and Dave.
I will submit my query on :Asp.Net Forum and Microsoft Docs.
Monday, July 13, 2020 8:17 AM -
You're welcome.
Regards, Dave Patrick ....
Microsoft Certified Professional
Microsoft MVP [Windows Server] Datacenter Management
Disclaimer: This posting is provided "AS IS" with no warranties or guarantees, and confers no rights.Monday, July 13, 2020 11:55 AM