小编Ada*_*ley的帖子

仅将 Azure AD 用于身份验证而非授权

我已经被这个问题困扰了几天了...

我想做的是使用 Azure AD 对用户进行身份验证,成功后,使用 ASP.NET Identity 自动登录以进行授权。如果他们没有帐户,我想自动创建一个。

本质上,Azure AD 只是确认它们是组织的一部分,ASP.NET 标识部分是它自己的数据库,我可以在其中使用该[Authorize]属性设置 Azure AD 之外的自定义角色。

这是我的ConfigureAuth()方法:

public void ConfigureAuth(IAppBuilder app)
    {
        // Configure the db context, user manager and signin manager to use a single instance per request
        app.CreatePerOwinContext(IntranetApplicationDbContext.Create);
        app.CreatePerOwinContext<ApplicationUserManager>(ApplicationUserManager.Create);
        app.CreatePerOwinContext<ApplicationSignInManager>(ApplicationSignInManager.Create);

        app.SetDefaultSignInAsAuthenticationType(CookieAuthenticationDefaults.AuthenticationType);

        app.UseCookieAuthentication(new CookieAuthenticationOptions());

        app.UseOpenIdConnectAuthentication(
            new OpenIdConnectAuthenticationOptions
            {
                ClientId = SettingsHelper.ClientId,
                Authority = SettingsHelper.Authority,

                Notifications = new OpenIdConnectAuthenticationNotifications()
                {
                    // If there is a code in the OpenID Connect response, redeem it for an access token …
Run Code Online (Sandbox Code Playgroud)

c# asp.net azure asp.net-identity azure-active-directory

3
推荐指数
1
解决办法
3298
查看次数