2017-09-14 7 views
1

私はIdentityServerを初めて使いました。我々は、アプリケーションが複数のWeb APIにアクセスできるようにするための要件を持っています。現在のところ、認証はデータベースを使用してローカルで行われ、Azure ADによって認証される別の方法があります。IdentityServer3を使用したAzure AD認証のローカルアカウントとオプション

私のダッシュボードアプリケーションはIdentityServer3(これまでは問題なく動作しています)を使用して認証し、代わりに外部プロバイダ(この場合はAzure AD)を使用して認証します。

私は

あなたに署名されたアプリケーションを決定するエラーがありますを取得しておくが。アプリケーションに戻ると、私は外部プロバイダのリストにAzureのADを追加している

CustomViewService found at here使用しています再び

サーバの設定を試してみてください。私は「

app.UseOpenIdConnectAuthentication(new OpenIdConnectAuthenticationOptions 
{ 

    ClientId = "xxxxxx-xxx-xxx-xx-04ec8dbxxxx", 
    Authority = "https://login.windows.net/[domain name]", 
    RedirectUri = "https://localhost:44333/core", 
    PostLogoutRedirectUri = "http://localhost:36336/", 
    AuthenticationType = "Azure AD", 
    Caption = "Azure AD", 
    TokenValidationParameters = new TokenValidationParameters 
    { 
    NameClaimType = "name", 
    RoleClaimType = "role" 
    }, 
    SignInAsAuthenticationType = "Cookies", 

    Notifications = new OpenIdConnectAuthenticationNotifications 
    { 
    MessageReceived = m => 
    { 
     var split = m.ProtocolMessage.AccessToken; 
     return Task.FromResult(0); 
    }, 
    AuthenticationFailed = context => 
    { 
     context.HandleResponse(); 
     context.Response.Redirect("/Error?message=" + context.Exception.Message); 
     return Task.FromResult(0); 
    }, 
    RedirectToIdentityProvider = (context) => 
    { 
     context.ProtocolMessage.DomainHint = "[domain name here]"; 
     return Task.FromResult(0); 
    } 
    } 
}); 

Azure ADログイン画面が表示され、その後アプリケーションはIdentityServ3に返信されます

私のクライアントはです10

クライアントの構成は次のとおりです。

public void Configuration(IAppBuilder app) 
{ 
    // For more information on how to configure your application, visit http://go.microsoft.com/fwlink/?LinkID=316888 
    JwtSecurityTokenHandler.InboundClaimTypeMap = new Dictionary<string, string>(); 

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

    app.UseOpenIdConnectAuthentication(new OpenIdConnectAuthenticationOptions 
    { 
    ClientId = "mvc.owin.hybrid.2", 
    Authority = "https://localhost:44333/core", 
    RedirectUri = "http://localhost:36336/", 
    PostLogoutRedirectUri = "http://localhost:36336/", 
    ResponseType = "code id_token", 
    Scope = "openid profile read write offline_access", 

    TokenValidationParameters = new TokenValidationParameters 
    { 
     NameClaimType = "name", 
     RoleClaimType = "role" 
    }, 

    SignInAsAuthenticationType = "Cookies", 

    Notifications = new OpenIdConnectAuthenticationNotifications 
    { 
     AuthorizationCodeReceived = async n => 
     { 
     // use the code to get the access and refresh token 
     var tokenClient = new TokenClient(
     "https://localhost:44333/core/connect/token", 
     "mvc.owin.hybrid.2", 
     "secret"); 

     var tokenResponse = await tokenClient.RequestAuthorizationCodeAsync(
     n.Code, n.RedirectUri); 

     if (tokenResponse.IsError) 
     { 
      throw new Exception(tokenResponse.Error); 
     } 

     // use the access token to retrieve claims from userinfo 
     var userInfoClient = new UserInfoClient(
     new Uri(n.Options.Authority + "/connect/userinfo"), 
     tokenResponse.AccessToken); 

     var userInfoResponse = await userInfoClient.GetAsync(); 

     // create new identity 
     var id = new ClaimsIdentity(n.AuthenticationTicket.Identity.AuthenticationType); 
     id.AddClaims(userInfoResponse.GetClaimsIdentity().Claims); 

     id.AddClaim(new Claim("access_token", tokenResponse.AccessToken)); 
     id.AddClaim(new Claim("expires_at", DateTime.Now.AddSeconds(tokenResponse.ExpiresIn).ToLocalTime().ToString())); 
     id.AddClaim(new Claim("refresh_token", tokenResponse.RefreshToken)); 
     id.AddClaim(new Claim("id_token", n.ProtocolMessage.IdToken)); 
     id.AddClaim(new Claim("sid", n.AuthenticationTicket.Identity.FindFirst("sid").Value)); 

     n.AuthenticationTicket = new AuthenticationTicket(
     new ClaimsIdentity(id.Claims, n.AuthenticationTicket.Identity.AuthenticationType, "name", "role"), 
     n.AuthenticationTicket.Properties); 
     }, 

     RedirectToIdentityProvider = n => 
     { 
     // if signing out, add the id_token_hint 
     if (n.ProtocolMessage.RequestType == OpenIdConnectRequestType.LogoutRequest) 
     { 
      var idTokenHint = n.OwinContext.Authentication.User.FindFirst("id_token"); 

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

     return Task.FromResult(0); 
     } 
    } 
    }); 
} 
+0

クライアントのプロパティでfalseにEnableLocalLoginを設定してくださいAzureのADのログイン画面に移動したい場合は

はさらに、あなたは(バイオリントレースまたは使用開発ツールを行うことができますF12)を使用して、Azure ADがIdentityServerに返答していることを確認しますか? Azure ADはトークンを戻しているのですか、エラーメッセージですか? – Saca

+0

紺碧の広告が正しく機能していて、私は灰色のabtユーザーのログを確認しました。 –

答えて

0

はそれを動作するように管理されます。

私が実装するAspNetIdentityUserService特別方法AuthenticateExternalAsync

を私はそれが働いたローカルユーザにアズールからユーザおよび特許請求の範囲にマッピングされたら忘れ。あなたは地元のログイン画面を非表示にする必要があり、クライアントが直接

関連する問題