2016-07-28 71 views
2

我是IdentityServer3的新手,剛剛開始設置它。它似乎進行得相當順利,我一直在爲類似於Kevin Dockx的Pluralsight課程(http://www.pluralsight.com/courses/building-securing-restful-api-aspdotnet) 中顯示的MVC應用程序開發Hybrid流程,當時我嘗試配置帶有MVC錯誤的IdentityServer彈出 - Microsoft.IdentityModel.Protocols.OpenIdConnectProtocolException: invalid_request帶有ServiceStack和MVC客戶端的IdentityServer3

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客戶端應用程序

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);   
    } 

的代碼,也有與012配置 https://github.com/MacLeanElectrical/servicestack-authentication-identityserver`驗證服務,但在Global.aspx中爲新的AppHost()。Init();它顯示錯誤 -

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

您需要打開日誌記錄 – leastprivilege

回答

1

這裏指定AllowedScopes如何我做我的

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; 
1

我不明白您在客戶端

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

我添加了作用域,但它顯示相同的錯誤 - 「Microsoft.IdentityModel.Protocols.OpenIdConnectProtocolException:invalid_request' – pc2307