2017-09-17 25 views
0

複数のASP.NetアプリケーションでSingle Sign OnサーバーとしてKeycloakを使用しようとしています。私はKeycloakOwinAuthenticationと呼ばれるGithub上のライブラリを見つけました。そして2つの異なるアプリケーションとして使用するために2回以内に提供されたサンプルコードをクローンしました。ASP.Netアプリケーション用のシングルサインオンソリューションとしてKeycloakを使用する

私は、Keycloakで同じレルム内の2つのアプリケーション(App1とApp2のを)構成されているすべての役割を持つテストユーザーを作成し、ログインしようとした

予想される動作:。、アプリ1からログインしApp2のをリフレッシュします自動的にログインしました

実際の結果:アプリケーション1からログインして、アプリケーション2を更新し、「/アプリケーション」で「サーバーエラー」を取得します。App1からログアウトしてApp2をリフレッシュしようとすると、正常に機能します。

私の2つのサンプルアプリケーションが見つかりましたhere ... My ActionResult for the protected p

[Authorize] 
    public ActionResult About() 
    { 
     ViewBag.Message = "Your application description page."; 
     var userPrincipal = User as ClaimsPrincipal; 
     ViewBag.Something = userPrincipal.Identity.ToString(); 
     return View(userPrincipal); 

    } 

と私のスタートアップページは、次のようになります:ビューにトークンを示した年齢は、次のようになります

public class Startup 
{ 
    public void Configuration(IAppBuilder app) 
    { 
     const string persistentAuthType = "Keycloak_Cookies"; 

     app.UseCookieAuthentication(new CookieAuthenticationOptions 
     { 
      AuthenticationType = persistentAuthType 
     }); 

     app.SetDefaultSignInAsAuthenticationType(persistentAuthType); 

     app.UseKeycloakAuthentication(new KeycloakAuthenticationOptions 
     { 
      Realm = "MyRealm", 
      ClientId = "App3", 
      ClientSecret = "KeycloakClientSecret", 
      KeycloakUrl = "http://localhost:8080/auth", 
      SignInAsAuthenticationType = persistentAuthType 
     }); 

私が見逃しているspeceficの設定はありますか?私はテストRealmと3つの異なるアプリケーション(Aspではなく)で動作するRealmを使用しましたが、すべてのクライアントでログインできませんでした。私は...すべてのクッキーがアクセス可能であることを確認するために、2つのタブで同じブラウザを使用していた

エラーテキスト:私は、全体のライブラリのコードをより深く行き、フラグがあることが分かっ

Server Error in '/' Application. 
IDX10214: Audience validation failed. Audiences: 'App1'. Did not match: validationParameters.ValidAudience: 'null' or validationParameters.ValidAudiences: 'null, App2' 
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. 

Exception Details: System.IdentityModel.Tokens.SecurityTokenInvalidAudienceException: IDX10214: Audience validation failed. Audiences: 'App1'. Did not match: validationParameters.ValidAudience: 'null' or validationParameters.ValidAudiences: 'null, App2' 
Source Error: An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below. 
+0

明日は変更または消滅するサードパーティサイトではなく、サンプルコードをここに掲載する必要があります:[mcve] – Rob

答えて

0

オーディエンスチェックが無効になります。これは、Startup.csファイルのKeycloak設定で設定する必要があります。フラグDisableAudienceValidationはデフォルトではfalseですが、設定に追加してその値をtrueに設定すると、オーディエンスの検証はスキップされます。

  app.UseKeycloakAuthentication(new KeycloakAuthenticationOptions 
     { 
      Realm = "DotNetApps", 
      ClientId = "TestingApp", 
      ClientSecret = "Client_Secret_Goes_Here", 
      KeycloakUrl = "http://localhost:8080/auth", 
      SignInAsAuthenticationType = persistentAuthType, 
      DisableAudienceValidation = true 

     }); 
関連する問題