首页 文章

Azure AD OpenIDConnect ASP.NET核心 - 身份验证和额外权限/令牌?

提问于
浏览
0

我在Azure AD上使用以下位来对ASP.NET Core进行身份验证 .

https://azure.microsoft.com/en-us/resources/samples/active-directory-dotnet-webapp-openidconnect-aspnetcore/

https://github.com/Azure-Samples/active-directory-dotnet-webapp-openidconnect-aspnetcore

创建Azure AD应用程序后,我有基本的登录/身份验证工作 . 用户可以登录/注销 .

我的问题是,当用户Auth登录到数据库时,最好的方法是什么?我考虑过将重定向URL设置为 endpoints ,保存,然后只是重定向回“Home”,但这是理想的吗?

此外,是否可以通过这种方法检索承载令牌?或者这是否需要其他类型的电话或扩展“范围”?例如,我可以检索经过身份验证的用户Manager .

https://graph.microsoft.com/v1.0/me/manager

1 回答

  • 1

    我的问题是,当用户Auth登录到数据库时,最好的方法是什么?我考虑过将重定向URL设置为 endpoints ,保存,然后只是重定向回“Home”,但这是理想的吗?

    这种方式只能记录已成功登录您应用的用户 . 它无法记录那些尝试登录您的应用但输入错误密码的用户 .

    Azure AD已提供大量报告,以便了解组织目录的完整性和安全性 . (请参阅here

    如果您使用的是Azure AD Premium,则可以通过以下Azure new portal查看登录活动:
    enter image description here

    如果您想在Web应用程序中存储登录活动,则可以在验证令牌后编写自定义代码 . 以下是供您参考的代码:

    // Configure the OWIN pipeline to use OpenID Connect auth.
    app.UseOpenIdConnectAuthentication(new OpenIdConnectOptions
     {
                ClientId = Configuration["AzureAD:ClientId"],
                Authority = String.Format(Configuration["AzureAd:AadInstance"], Configuration["AzureAd:Tenant"]),
                ResponseType = OpenIdConnectResponseType.IdToken,
                PostLogoutRedirectUri = Configuration["AzureAd:PostLogoutRedirectUri"],
                Events = new OpenIdConnectEvents
                {
                    OnRemoteFailure = OnAuthenticationFailed,
                    OnTokenValidated = context => {
                        //write the custom code to store users login-in                         
                        return Task.FromResult(0); }
                },
    
    });
    

    此外,是否可以通过这种方法检索承载令牌?

    是 . 我们可以在收到授权码后获得令牌 . 您可以参考代码示例here以从asp.net核心应用程序获取令牌 .

相关问题