成功获取具有身份验证代码的令牌后,MSAL返回空用户

时间:2019-04-11 18:58:04

标签: azure msal

在以下代码中,即使前面的AcquireTokenByAuthorizationCode确实返回了访问权限和ID令牌,GetUserAccount仍返回空用户。我希望它不会为空。在我后面的代码中,无提示获取显然会失败,因为用户仍然为null。我想念什么?

var code = ctx.Code;
string signedInUserID = ctx.AuthenticationTicket.Identity.FindFirst(System.IdentityModel.Claims.ClaimTypes.NameIdentifier).Value;
TokenCache userTokenCache = new MSALSessionCache(signedInUserID, ctx.OwinContext.Environment["System.Web.HttpContextBase"] as HttpContextBase).GetMsalCacheInstance();
var capp = new ConfidentialClientApplication(
    clientId,
    String.Format("https://login.microsoftonline.com/tfp/{0}.onmicrosoft.com/{1}/v2.0/.well-known/openid-configuration", "b2cdom", "B2C_1_BasicSUSI"
),
    "https://localhost:44368/",
    new ClientCredential(
        ConfigurationManager.AppSettings["ida:Secret"]),
        userTokenCache,
        null
);
capp.ValidateAuthority = false;
var tokens = await capp.AcquireTokenByAuthorizationCodeAsync(
    code,
    new string[] { "https://mrochonb2cprod.onmicrosoft.com/webapiill/read" }
);
var user = await capp.GetAccountAsync(signedInUserID);

0 个答案:

没有答案