微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

asp.net-mvc – thinktecture identityserver v3

尝试使用Thinctecture identityserver v3作为多个mvc应用程序的简单sts.
我能够遍历所提供的示例应用程序并且运行正常,但它们都使用嵌入式身份服务器.我需要将identityserver作为一个单独的应用程序,以便我可以将它用作多个应用程序的sts.当我尝试运行身份服务器并将示例mvc应用程序连接到它时似乎缺少某些东西.

示例mvc应用程序使用武士刀

app.USEOpenIdConnectAuthentication(new OpenIdConnectAuthenticationoptions...

但我只是不明白如何正确配置外部应用服务.
我的猜测是我没有使用正确的端点.

这是我的依赖方配置为mvc.
然后我在这里运行最新的IS v3:
:44333

在mvc应用程序中,每当我尝试导航到需要授权的视图时,我都会得到异常.

堆栈跟踪:

[HttpRequestException: Response status code does not indicate success: 404 (Not Found).]
   System.Net.Http.HttpResponseMessage.EnsureSuccessstatusCode() +87960
   Microsoft.IdentityModel.Protocols.<GetDocumentAsync>d__0.MoveNext() +496

[IOException: Unable to get document from: https://localhost:44333/.well-kNown/openid-configuration]
   Microsoft.IdentityModel.Protocols.<GetDocumentAsync>d__0.MoveNext() +830
   System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) +93
   System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) +52
   System.Runtime.CompilerServices.TaskAwaiter`1.GetResult() +24
   Microsoft.IdentityModel.Protocols.<GetAsync>d__0.MoveNext() +512
   System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) +93
   System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) +52
   System.Runtime.CompilerServices.TaskAwaiter`1.GetResult() +24
   Microsoft.IdentityModel.Protocols.<GetConfigurationAsync>d__3.MoveNext() +1332

这是mvc应用程序中的完整身份验证配置.

app.USEOpenIdConnectAuthentication(new OpenIdConnectAuthenticationoptions
{
    //Authority = "https://localhost:44319/identity",Authority = "https://localhost:44333",ClientId = "mvc",Scope = "openid profile roles",RedirectUri = "https://localhost:44319/",SignInAsAuthenticationType = "Cookies",UsetokenLifetime = false,Notifications = new OpenIdConnectAuthenticationNotifications
    {
        SecurityTokenValidated = async n =>
            {
                var id = n.AuthenticationTicket.Identity;

                // we want to keep first name,last name,subject and roles
                var givenname = id.FindFirst(Constants.ClaimTypes.Givenname);
                var familyName = id.FindFirst(Constants.ClaimTypes.FamilyName);
                var sub = id.FindFirst(Constants.ClaimTypes.Subject);
                var roles = id.FindAll(Constants.ClaimTypes.Role);

                // create new identity and set name and role claim type
                var nid = new ClaimsIdentity(
                    id.AuthenticationType,Constants.ClaimTypes.Givenname,Constants.ClaimTypes.Role);

                nid.AddClaim(givenname);
                nid.AddClaim(familyName);
                nid.AddClaim(sub);
                nid.AddClaims(roles);

                // keep the id_token for logout
                nid.AddClaim(new Claim("id_token",n.ProtocolMessage.IdToken));

                // add some other app specific claim
                nid.AddClaim(new Claim("app_specific","some data"));

                n.AuthenticationTicket = new AuthenticationTicket(
                    nid,n.AuthenticationTicket.Properties);
            },RedirectToIdentityProvider = async n =>
            {
                if (n.ProtocolMessage.RequestType == OpenIdConnectRequestType.logoutRequest)
                {
                    var idTokenHint = n.OwinContext.Authentication.User.FindFirst("id_token");

                    if (idTokenHint != null)
                    {
                        n.ProtocolMessage.IdTokenHint = idTokenHint.Value;
                    }
                }
            }
    }
});

解决方法

您的端点最后缺少/ identity

原文地址:https://www.jb51.cc/aspnet/247224.html

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐