带有ServiceStack和MVC客户端的IdentityServer3 [英] IdentityServer3 with ServiceStack and MVC Client

查看:96
本文介绍了带有ServiceStack和MVC客户端的IdentityServer3的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是IdentityServer3的新手,才刚刚开始进行设置.一切似乎进展顺利,我一直在为MVC应用开发混合流程,类似于Kevin Dockx的Pluralsight课程(

I'm new to IdentityServer3 and am just starting to get it set up. It seems to be going quite well and I've been working on the Hybrid flow for an MVC app similar to that shown in Kevin Dockx's Pluralsight course (http://www.pluralsight.com/courses/building-securing-restful-api-aspdotnet) when I tried to configure IdentityServer with MVC error is pops up- Microsoft.IdentityModel.Protocols.OpenIdConnectProtocolException: invalid_request

ID服务器:

new Client
{
   Enabled = true,
   ClientName = "MVC Client (Hybrid Flow)",
   ClientId = "mvc",
   Flow = Flows.Hybrid,
   RequireConsent = true,
   RedirectUris = new List<string>
   {"https://localhost:44358/"},                    
}

 var scopes = new List<Scope>{                    
    StandardScopes.OpenId,
    StandardScopes.Profile
 };

以下是MVC客户端应用程序中的代码

And the following is the code from the MVC client app

public void Configuration(IAppBuilder app)
    {            
        app.UseCookieAuthentication(new CookieAuthenticationOptions
        {
            AuthenticationType = "Cookies",
            //CookieName = "ourcookiename"
        });

        var options = new OpenIdConnectAuthenticationOptions
        {
            ClientId = "mvc",
            Authority = "https://localhost:44367/identity/",
            RedirectUri = "https://localhost:44358/",
            // PostLogoutRedirectUri = "https://localhost:44300/",
            SignInAsAuthenticationType = "Cookies",
            ResponseType = "code id_token token",
            Scope = "openId profile"
        };
        app.UseOpenIdConnectAuthentication(options);         
    }

,还必须使用ServiceStack' for this I used link https://github.com/配置IdentityServer3 MacLeanElectrical/servicestack-authentication-identityserver `来对服务进行身份验证,但在Global.aspx中用于新的AppHost().Init();它显示错误-

And also have to configure IdentityServer3 with ServiceStack' for this I used linkhttps://github.com/MacLeanElectrical/servicestack-authentication-identityserver` to authenticate service but in Global.aspx for new AppHost().Init(); it shows error-

'System.NullReferenceException' occurred in ServiceStack.dll but was not handled in user code

推荐答案

这是我的工作方式

return new[]
        {
            new Client
            {
                Enabled = true,
                ClientId = "Client",
                ClientName = "SomeClient",
                Flow = Flows.Hybrid,
                RequireConsent = true,
                AllowedScopes = new List<string>
                {
                    "openid",
                    "profile",
                    "roles",
                    "api",
                    "offline_access"
                },
                RedirectUris = new List<string>
                {
                    Constants.Client
                },

                AccessTokenLifetime = 3600,

                ClientSecrets = new List<Secret>()
                {
                    new Secret("secret".Sha256())
                }
            }
        };


var scopes = new List<Scope>
        {

            //Identity Scopes
            StandardScopes.OpenId,
            StandardScopes.Profile,

            new Scope
            {
                Enabled = true,
                Name = "roles",
                DisplayName = "Roles",
                Description = "The roles you belong to.",
                Type = ScopeType.Identity,
                Claims = new List<ScopeClaim>
                {
                    new ScopeClaim("role")
                }
            },
            new Scope
            {
                Enabled = true,
                Name="api",
                DisplayName = "API Scope",
                Description = "To accesss the API",
                Type = ScopeType.Resource,
                Emphasize = false,
                Claims = new List<ScopeClaim>
                {
                    new ScopeClaim("role"),
                    new ScopeClaim("id")
                }

            },

            StandardScopes.OfflineAccess

        };

        return scopes;

这篇关于带有ServiceStack和MVC客户端的IdentityServer3的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆