简体   繁体   English

Azure AD B2C:AcquireTokenSilentAsync返回空访问令牌

[英]Azure AD B2C: AcquireTokenSilentAsync returns empty access token

I followed the steps in Create an ASP.NET web app with Azure Active Directory B2C sign-up, sign-in, profile edit, and password reset and used the sample code to prototype Azure AD B2C for our company. 我按照创建ASP.NET Web应用程序中的步骤进行了Azure Active Directory B2C注册,登录,配置文件编辑和密码重置,并使用示例代码为我们公司的Azure AD B2C原型。

  • The only change is that I used my domain name instead of the sample domain and modified the web.config 唯一的变化是我使用了我的域名而不是示例域并修改了web.config
  • I have defined the scope and App ID for API application 我已经为API应用程序定义了范围和App ID
  • I get the Id token but not the access token 我得到了Id令牌,但没有获得访问令牌

Any suggestion on what the issue could be? 关于问题可能是什么的任何建议?

在此输入图像描述

One of the steps is missing in Create an ASP.NET web app with Azure Active Directory B2C sign-up, sign-in, profile edit, and password reset documentation. 使用Azure Active Directory B2C注册,登录,配置文件编辑和密码重置文档创建ASP.NET Web应用程序时,缺少其中一个步骤。

The access token is returned once you give the API access to Web Application following the steps described here . 按照此处描述的步骤授予对Web应用程序的API访问权限后,将返回访问令牌。

I had this problem when everything about my request was correct except the scope I was requesting. 当我的请求的所有内容都正确时,我遇到了这个问题, 除了我要求的范围。 I would get an id_token returned, but not an access_token. 我会得到一个id_token返回,但不是access_token。 I was using the sample from here: https://dzimchuk.net/setting-up-your-asp-net-core-2-0-apps-and-services-for-azure-ad-b2c/ (a superb article by the way). 我正在使用这里的样本: https//dzimchuk.net/setting-up-your-asp-net-core-2-0-apps-and-services-for-azure-ad-b2c/ (一篇精湛的文章顺便说说)。 I had run the app but without having defined the read_values scope in the Application Published Scopes in my Azure B2C tenant. 我已经运行了应用程序但没有在Azure B2C租户中的Application Published Scopes中定义read_values范围。 The issue you describe manifested itself in these lines of code from that sample. 您描述的问题在该示例的这些代码行中表现出来。

var result = await client.AcquireTokenByAuthorizationCodeAsync(context.TokenEndpointRequest.Code, new[] { $"{authOptions.ApiIdentifier}/read_values" });

context.HandleCodeRedemption(result.AccessToken, result.IdToken); 

result.IdToken was fine, result.AccessToken was null until I correctly defined the read_values scope in my azure b2c tenant. result.IdToken很好,result.AccessToken为null,直到我在我的azure b2c租户中正确定义了read_values范围。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM