2017-03-23 3 views
0

私はIdentityServerとOpenId Connectを初めて使用しています。私は.NET Framework 6とIdentityServer3とOpenId Connectで作業しています。 IdentityServer3ドキュメントの概要セクション(コンソールクライアント、MVCクライアント、およびJavaScriptクライアント)の3つのウォークスルーを経て、これらの実用的なソリューションをモデルとして取り上げました。私は現在、テスト目的で単純なMVCクライアントを使用して独自の認証サービスを構築しようとしています。動いていない。その動作しないという症状は、ホームコントローラーの[Authorize]属性で保護されているMVCクライアントの[バージョン情報]ページで、ユーザーがログインページにリダイレクトされずにHTTP 401.0 - Unauthorizedと報告されることです。私はChromeデベロッパーツールのネットワークトラフィックを見直し、/ Home/HTTP 401を返すについての最初のリクエストを見てきました。予想されるHTTP 302リダイレクトはありません。単純なIdentityServer3/OpenIdConnectソリューションが動作しない - HTTP 401.0 - 無許可

マイIdentityServer3の構成は次のようになります。

public class Startup 
{ 
    public void Configuration(IAppBuilder app) 
    { 
     // TODO: Replace use of InMemoryUsers with custom Orvis UserService 
     app.UseIdentityServer(new IdentityServerOptions 
     { 
      SiteName = "MyClient Authentication Service", 
      SigningCertificate = LoadCertificate(), 
      Factory = new IdentityServerServiceFactory() 
      .UseInMemoryClients(Clients.Get()) 
      .UseInMemoryScopes(Scopes.Get()) 
      .UseInMemoryUsers(Users.Get().ToList()), 
      RequireSsl = true 
     }); 
    } 

    X509Certificate2 LoadCertificate() 
    { 
     // TODO: Get real signing certificate? 
     return new X509Certificate2(string.Format(@"{0}\bin\idsrv3test.pfx", AppDomain.CurrentDomain.BaseDirectory), "idsrv3test"); 
    } 
} 

GetClientsとGetScopesコードは次のようになります。

public static IEnumerable<Client> Get() 
{ 
    // TODO: Replace hard-coded implementation of Clients.Get() with a configuration-driven implementation 
    return new List<Client> 
    { 
     new Client 
     { 
      Enabled = true, 
      ClientId = "mvc-sample", 
      ClientName = "MVC Sample Client", 
      RequireConsent = false, 
      Flow = Flows.Implicit, 
      RedirectUris = new List<string> { "http:/localhost:37320" }, 
      AllowedCorsOrigins = new List<string> { "http://localhost:37320/" }, 
      AllowedScopes = new List<string> { "orvis-services", "orvis-shopper-service" } 
     } 
    }; 
} 

public static IEnumerable<Scope> Get() 
{ 
    return new List<Scope> 
    { 
     new Scope 
     { 
      Name = "all-services", 
      DisplayName = "All Services", 
      Description = "Access to all microservices", 
      Type = ScopeType.Resource 
     }, 
     new Scope 
     { 
      Name = "shopper-service", 
      DisplayName = "Shopper Service", 
      Description = "Access to the Shopper microservice", 
      Type = ScopeType.Resource 
     } 
    }; 
} 

そして、私のクライアントの設定は次のようになります。だから、

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

    app.UseOpenIdConnectAuthentication(new OpenIdConnectAuthenticationOptions 
    { 
     Authority = "https://localhost:44332", 
     ClientId = "mvc-sample", 
     RedirectUri = "http://localhost:37320", 
     ResponseType = "id_token", 
     SignInAsAuthenticationType = "Cookies" 
    }); 
} 

IdentityServer3「入門:MVC認証およびWeb APIと非常によく似ています"歩いていく。 1つの違いは、ウォークスルーにはクライアントとサーバーのコードが同じプロジェクトに含まれており、それらを別々のプロジェクトに分割している点です。

devツールのネットワークタブには、期待されている302応答ではなく401.0応答で/ Home/Aboutに要求が表示されるため、私はCilent設定に問題があると思われます。しかし、ブラウザの開発ツールを超えて、私はどこに根底にある詳細を得るために見えるか分からない。

感謝の意を表します。

+0

ログが有効になっていますか? [https://identityserver.github.io/Documentation/docsv2/configuration/logging.html](https://identityserver.github.io/Documentation/docsv2/configuration/logging.html) –

+0

私はできません。しかし、何らかの理由で、MVCクライアントのStartup.Configuration()メソッドが実行されていないと判断しました。したがって、OpenId Connectは設定されていません。だから私はIdentityServerのロギングがこの時点で私を助けてくれるとは思わない。それは良い提案でしたが。 – user3498540

答えて

0

問題は、1つのプロジェクトでIdentityServerとMVCクライアントをモデルとして使用していたIdentityServer3のウォークスルーに問題があったことです。別に作成したときは、Microsoft.Owin.Host.SystemwebとIdentityServer3パッケージをIdentityServerプロジェクトに追加し、Microsoft.Owin.Security.CookiesパッケージとMicrosoft.Owin.Security.OpenIdConnectパッケージをMVCクライアントプロジェクトに追加しました。 MVCクライアントプロジェクトにはMicrosoft.Owin.Host.Systemwebパッケージも必要であることが判明しました。それがなければStartup.Configuration()メソッドは呼び出されません。

関連する問題