【问题标题】:Using OpenID Connect OWIN module as an identity provider in IdentityServer3在 IdentityServer3 中使用 OpenID Connect OWIN 模块作为身份提供者
【发布时间】:2016-04-24 18:37:22
【问题描述】:

我在 asp.net v5 环境中运行 IdentityServer3。我正在尝试将 OWIN OpenID Connect 模块连接为身份提供者,以便用户可以使用本地凭据或联合出 Azure AD 实例的凭据通过 IDS3 登录。这是我的设置:

身份提供者配置:

 public static void ConfigureIdentityProviders(IAppBuilder app, string signInAsType)
        {         
            app.UseOpenIdConnectAuthentication(
                new OpenIdConnectAuthenticationOptions
                {
                    ClientId = "a-valid-client-id",
                    Authority = "https://login.microsoftonline.com/some-valid-authority",
                    PostLogoutRedirectUri = "https://localhost:44300/",
                    SignInAsAuthenticationType = OpenIdConnectAuthenticationDefaults.AuthenticationType,
                    CallbackPath = new PathString("/identity/callback"),
                    ResponseType = "code id_token token"
                });
        }

IDS3 配置:

  app.Map("/identity", idsrvApp =>
            {                
                idsrvApp.UseIdentityServer(new IdentityServerOptions()
                {
                    SiteName = "Identity Server",
                    SigningCertificate = LoadCertificate(),
                    AuthenticationOptions = new AuthenticationOptions()
                    {
                        IdentityProviders = ConfigureIdentityProviders
                    },

                    Factory = new IdentityServerServiceFactory()
                        .UseInMemoryUsers(Users.Get())
                        .UseInMemoryClients(Clients.Get())
                        .UseInMemoryScopes(StandardScopes.All)
                });            
            });

这部分工作正常,Azure 将令牌作为 POST 请求返回到指定的端点。我收到以下错误:

{"Message":"The requested resource does not support http method 'POST'."}

我尝试了各种不同的重定向 URL - 例如,重定向到“/”,重定向到“/identity”中的其他页面,但总是得到相同的错误。我不确定是否应该在回发 URL 上安装一些资源来显式处理令牌,但我的印象是 OWIN 应该为我处理这个?

我开始认为这可能是我在 ASP.net 5 中使用 OWIN 中间件引起的问题。

谢谢!

【问题讨论】:

  • 我建议你看看ASOS。我目前正在使用它,并且对它有很好的体验。有一些示例可以帮助您启动和运行。
  • 如果您只有一个 oidc ext 提供程序 - 您不需要设置回调路径 - 可以尝试不设置它以消除一种可能的错误来源
  • 好的提示 - 将其关闭并进一步发展。谢谢!

标签: asp.net-mvc asp.net-core identityserver3


【解决方案1】:

问题是 Azure AD 将令牌返回到的重定向 URI 与 OID 连接上配置的不同。发生这种不匹配时,不会在返回 URL 上侦听 POST 并且您会收到上述错误。

在此之后,我收到的下一个问题是“错误识别调用应用程序”,在 IDS3 中的令牌返回端点上弹出。通过向 OID Connect 对象添加以下配置解决了这个问题:

TokenValidationParameters = new TokenValidationParameters
                    {
                        AuthenticationType = IdentityServer3.Core.Constants.ExternalAuthenticationType
                    }

【讨论】:

    猜你喜欢
    • 2017-10-14
    • 2017-05-14
    • 1970-01-01
    • 2016-12-18
    • 2017-09-13
    • 1970-01-01
    • 1970-01-01
    • 2014-04-25
    • 1970-01-01
    相关资源
    最近更新 更多