アクセストークンを取得して保存できるようにしようとしていて、後でExchangeServiceに渡します。 Startup.Authは次のようになります。MVCアプリケーションでアクセストークンを取得
app.UseOpenIdConnectAuthentication(
new OpenIdConnectAuthenticationOptions
{
ClientId = clientId,
Authority = authority,
UseTokenLifetime = false,
/*
* Skipping the Home Realm Discovery Page in Azure AD
* http://www.cloudidentity.com/blog/2014/11/17/skipping-the-home-realm-discovery-page-in-azure-ad/
*/
Notifications = new OpenIdConnectAuthenticationNotifications
{
RedirectToIdentityProvider = OpenIdConnectNotification.RedirectToIdentityProvider,
MessageReceived = OpenIdConnectNotification.MessageReceived,
SecurityTokenReceived = OpenIdConnectNotification.SecurityTokenReceived,
SecurityTokenValidated = OpenIdConnectNotification.SecurityTokenValidated,
AuthorizationCodeReceived = OpenIdConnectNotification.AuthorizationCodeReceived,
AuthenticationFailed = OpenIdConnectNotification.AuthenticationFailed
},
});
その後、SecurityTokenValidatedに、私はこれをしなかった:
public static async Task<Task> SecurityTokenValidated(SecurityTokenValidatedNotification<OpenIdConnectMessage, OpenIdConnectAuthenticationOptions> context)
{
string aadInstance = ConfigurationManager.AppSettings["ida:AADInstance"];
string clientId = ConfigurationManager.AppSettings["ida:ClientId"];
var authContext = new AuthenticationContext(aadInstance + "/oauth2/token", false);
var authResult =await authContext.AcquireTokenByAuthorizationCodeAsync(context.ProtocolMessage.Code,
new Uri(aadInstance), new ClientAssertion(clientId, "5a95f1c6be7bf3c61f6392ec84ddd044acef61d9"));
var accessToken = authResult.Result.AccessToken;
context.AuthenticationTicket.Identity.AddClaim(new Claim("access_token", accessToken));
return Task.FromResult(0);
}
私はすべてのエラーを得ることはありませんが、アプリケーションは、この行にハング:
var accessToken = authResult.Result.AccessToken;
ClientAssertionは、私がIISにインストールしたSSL証明書の拇印を使用して作成されました。証明書が間違ったタイプであるかどうかは分かりません。
更新: Sacaのコメントを反映するようにSecurityTokenValidatedを更新しましたが、「AADSTS50027:無効なJWTトークン」が表示されます。トークン形式ではない有効な「エラーこのよう また、私はこのコードを試してみました:。
string aadInstance = ConfigurationManager.AppSettings["ida:AADInstance"];
string clientId = ConfigurationManager.AppSettings["ida:ClientId"];
var authContext = new AuthenticationContext(aadInstance, false);
var cert = new X509Certificate2("...", "...");
var cacert = new ClientAssertionCertificate(clientId, cert);
var authResult = await authContext.AcquireTokenByAuthorizationCodeAsync(context.ProtocolMessage.Code, new Uri(aadInstance), cacert);
var accessToken = authResult.AccessToken;
context.AuthenticationTicket.Identity.AddClaim(new Claim("access_token", accessToken));
return Task.FromResult(0);
が、私が手にこの方法」AADSTS70002:エラーの検証の資格情報を。 AADSTS50012:クライアントのアサーションが無効な署名が含まれています」
これは吊り部分を修正しましたが、まだaccess_tokenはありません。アプリケーションが読み込まれ、トークンにアクセスしようとしているときにクレームがそこにありません。 –
うーん...私はIEでテストしようとしたので、クロームがいくつかのものをキャッシュしたと思います。トークンがありません。質問は今私の要求に悪いことをどのように見つけ出すのですか? :( –