私はstackoverflowOpenID Azureアクセストークンでこのリンクを通過しました。また、GitHubで複数の例を通過しました。シナリオを説明しましょう。
専用ログインを備えたASP.NETMVC Webアプリがありますが、クライアントからAzure Active Directoryとのブレンドを要求されたため、Start_up.cs
ファイルにコードを追加することでブレンドできます(でsecurity_token
認証トークンを検証していません)。すべて。必要ですか?)
public void ConfigureAuth(IAppBuilder app)
{
string clientId = ConfigurationManager.AppSettings["ida:ClientID"];
//string appKey = ConfigurationManager.AppSettings["ida:Password"];
string tenantid = ConfigurationManager.AppSettings["tenantid"];
//string graphResourceID = "https://graph.windows.net";
string redirectUrl = ConfigurationManager.AppSettings["redirectUrl"];
//fixed address for multitenant apps in the public cloud
string authority = String.Format(System.Globalization.CultureInfo.InvariantCulture, ConfigurationManager.AppSettings["Authority"], tenantid);
app.SetDefaultSignInAsAuthenticationType(CookieAuthenticationDefaults.AuthenticationType);
app.UseCookieAuthentication(new CookieAuthenticationOptions {
CookieSecure = CookieSecureOption.Always,
});
app.UseOpenIdConnectAuthentication(
new OpenIdConnectAuthenticationOptions
{
ClientId = clientId,
Authority = authority,
RedirectUri = redirectUrl,
PostLogoutRedirectUri = redirectUrl,
Scope = OpenIdConnectScopes.OpenIdProfile,
ResponseType = OpenIdConnectResponseType.CodeIdToken,
TokenValidationParameters = new System.IdentityModel.Tokens.TokenValidationParameters
{
ValidateIssuer = false,
},
Notifications = new OpenIdConnectAuthenticationNotifications()
{
AuthenticationFailed = (context) =>
{
context.OwinContext.Response.Redirect("/Home/Error");
context.HandleResponse(); // Suppress the exception
return Task.FromResult(0);
}
}
});
}
私は使用します
[Authorize]
コントローラーで確認するために、リクエストは認証され、適切なビューにリダイレクトされます。
しかし、私のクライアントは、access_tokenベースのアクセスを有効にするように特に要求しています。同じようにグラフAPIチュートリアルを使用しようとしています。
Graph APIを使用し、以下にこの種のコードを追加して、access_tokenを取得するための正しいアプローチを使用していますか(参照のみ)?
AuthorizationCodeReceived = async (context) =>
{
var code = context.Code;
ClientCredential credential = new ClientCredential(clientId, appKey);
string tenantID = context.AuthenticationTicket.Identity.FindFirst("http://schemas.microsoft.com/identity/claims/tenantid").Value;
string signedInUserID = context.AuthenticationTicket.Identity.FindFirst(ClaimTypes.NameIdentifier).Value;
AuthenticationContext authContext = new AuthenticationContext(string.Format("https://login.microsoftonline.com/{0}", tenantID), new EFADALTokenCache(signedInUserID));
AuthenticationResult result = await authContext.AcquireTokenByAuthorizationCodeAsync(
code, new Uri(HttpContext.Current.Request.Url.GetLeftPart(UriPartial.Path)), credential, graphResourceID);
if(result!=null)
{
Console.WriteLine("access code received");
}
},
SecurityTokenValidated = (context) =>
{
return Task.FromResult(0);
}
access_tokenを取得するために他の手段を使用する必要がありますか(grant_typeなどを使用した例はたくさんありますが、もっと混乱します)access_tokenは本当にこのシナリオに適合しますか?
注:これはばかげた質問に聞こえるかもしれませんが、今がその時であり、私はこの混乱を解消しなければなりません。
OpenID Connectでは、ユーザーは認証され、Cookieベースの認証を介してSSOできます。認証が完了し、ユーザーを表すトークンがアプリケーションに送信された後、OWINミドルウェアはセッションCookieを作成します。その後、ブラウザは後続のリクエストでこのCookieを使用するため、ユーザーはパスワードを再入力する必要がなく、追加の確認も必要ありません。
あなたが説明していることから、あなたはトークンベースの認証を有効にしているようであり、クライアントの要件を満たしているはずです。
追加のドキュメントについては、次のリポジトリを参照してください:https://github.com/Azure-Samples/active-directory-dotnet-webapp-openidconnect
この記事はインターネットから収集されたものであり、転載の際にはソースを示してください。
侵害の場合は、連絡してください[email protected]
コメントを追加