私は、Microsoftの権限に対してOpenIdConnectAuthenticationを使用しようとしています。私は認証することができますが、アクセストークンを取得しようとすると、呼び出しが失敗し、私が再認証することができます。私は決して適切なトークンを引き出さないようです。アクセストークンを取得するコードは次のとおりです。ConfidentialClientApplication AcquireTokenSilentAsyncは常に失敗します
public async Task<string> GetUserAccessTokenAsync()
{
string signedInUserID = ClaimsPrincipal.Current.FindFirst(ClaimTypes.NameIdentifier).Value;
//string signedInUserID = User.Identity.GetUserId();
tokenCache = new MSALSessionCache(
signedInUserID,
HttpContext.Current.GetOwinContext().Environment["System.Web.HttpContextBase"] as HttpContextBase);
var cachedItems = tokenCache.ReadItems(appId); // see what's in the cache
ConfidentialClientApplication cca = new ConfidentialClientApplication(
appId,
redirectUri,
new ClientCredential(appSecret),
tokenCache);
try
{
AuthenticationResult result = await cca.AcquireTokenSilentAsync(scopes.Split(new char[] { ' ' }));
return result.Token;
}
// Unable to retrieve the access token silently.
catch (MsalSilentTokenAcquisitionException)
{
HttpContext.Current.Request.GetOwinContext().Authentication.Challenge(
new AuthenticationProperties() { RedirectUri = "/" },
OpenIdConnectAuthenticationDefaults.AuthenticationType);
//throw new Exception("Resource.Error_AuthChallengeNeeded");
return null;
}
}
私には何が欠けているのか分かりません。私は今まで私を導くためにMicrosoft Graph REST ASPNET Connectサンプルを使用しました。私の最終目標は、ユーザーを認証し、そのプロファイルとMS残りのAPIからいくつかの項目を使用することです。