3

thisチュートリアルを使用してidentityserver3とMVC4クライアントをセットアップしました。私がクライアントに 'Implicit'フローを使用するように設定したとき、物事は予想どおりに機能していて、私は 'profile'スコープに戻ります。つまり、私はクレームfirst_nameとgiven_nameを見つけることができます。私の設定コードの下に。Identityserver3 - HybridFlowがプロファイルスコープを返さない

クライアントとユーザーの設定

public static class Users 
{ 
    public static List<InMemoryUser> Get() 
    { 
     return new List<InMemoryUser> 
     { 
      new InMemoryUser 
      { 
       Username = "Bob",Password = "password",Subject = "1", 
       Claims = new [] 
       { 
        new Claim(Constants.ClaimTypes.GivenName,"firstName"), 
        new Claim(Constants.ClaimTypes.FamilyName,"lastName") 
       } 
      } 
     }; 
    } 
} 

public static class Clients 
{ 
    public static IEnumerable<Client> Get() 
    { 
     return new[] 
     { 
      new Client 
      { 
       ClientId = "MVC", 
       ClientName = "MVC Client Name", 
       RedirectUris = new List<string> 
       { 
        "https://localhost:44302/" 
       }, 
       Flow = Flows.Implicit, 
       AllowAccessToAllScopes = true 
      } 
     }; 
    } 
} 

私は 'コンタクト'

[Authorize] 
public ActionResult Contact() 
{    
    ClaimsPrincipal principal = User as ClaimsPrincipal; 
    return View(principal.Claims); 
} 
という名前のホームコントローラのアクションを確保してきた私のMVCアプリケーションで

public void Configuration(IAppBuilder app) 
{ 
    JwtSecurityTokenHandler.InboundClaimTypeMap = new Dictionary<string, string>(); 

    app.Map("/identity", appBuilder => { 
    appBuilder.UseIdentityServer(new IdentityServer3.Core.Configuration.IdentityServerOptions 
    { 
     SiteName = "Site Name", 
     SigningCertificate = LoadCertificate(), 
     RequireSsl = false, 
     Factory = new IdentityServer3.Core.Configuration.IdentityServerServiceFactory() 
      .UseInMemoryClients(Clients.Get()) 
      .UseInMemoryUsers(Users.Get()) 
      .UseInMemoryScopes(StandardScopes.All) 
     }); 
    }); 

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

    app.UseOpenIdConnectAuthentication(new OpenIdConnectAuthenticationOptions 
    { 
     Authority = "https://localhost:44302/identity", 
     ClientId = "MVC", 
     RedirectUri = "https://localhost:44302/", 
     ResponseType = "id_token",     
     SignInAsAuthenticationType = "Cookies", 
     Scope = "openid profile" 
    }); 
} 

のIdentity Serverの設定

そして最後に、ここでは単純なビューにある

@model IEnumerable<System.Security.Claims.Claim> 
@foreach (var item in Model) 
{ 
    <div> 
     <span>@item.Type</span> 
     <span>@item.Value</span> 
    </div> 
} 
</div> 

私はこのアプリを実行すると、セキュアな「コンタクト」のリンクをクリックした後、私は、サーバーをSTSにリダイレクトされていますし、資格情報を提供した後、私は出力の下に見ることができます。

Output

はSTSによって返され、特許請求の範囲内に存在するGIVEN_NAMEFAMILY_NAMEを主張注意。

問題:私はハイブリッドフローをサポートするために、クライアントを変更

瞬間。私はが戻っを得ていないが、私は私のコードの変更の下に作られたGIVEN_NAMEFAMILY_NAME

を主張しています。

クライアント構成

public static IEnumerable<Client> Get() 
    { 
     return new[] 
     { 
      new Client 
      { 
       ClientId = "MVC", 
       ClientName = "MVC Client Name", 
       RedirectUris = new List<string> 
       { 
        "https://localhost:44302/" 
       }, 
       Flow = Flows.Hybrid,//Changed this to Hybrid 
       AllowAccessToAllScopes = true 
      } 
     }; 
    } 

サーバー構成

app.UseOpenIdConnectAuthentication(new OpenIdConnectAuthenticationOptions 
     { 
      Authority = "https://localhost:44302/identity", 
      ClientId = "MVC", 
      RedirectUri = "https://localhost:44302/", 
      ResponseType = "code id_token token", //Changed response type    
      SignInAsAuthenticationType = "Cookies", 
      Scope = "openid profile" 
     }); 

applicatonを実行した後、私はSTSによって返されたクレームの下に見ることができます

enter image description here

GIVEN_NAMEFAMILY_NAMEにを主張

(注)この時間が不足しています。

私は何かを見逃しましたか?

+0

私はハイブリッドフローと同じ問題があります。どのように解決しましたか? – barteloma

答えて

3

id_tokenのみを要求すると、そのユーザーのすべてのクレームがid_tokenにあります。トークンを取得する要求を変更すると(コードまたはトークンを要求することによって)、「AlwaysInclude」として構成されたユーザー主張のみがid_tokenに含まれます。残りは、受け取ったaccess_tokenを使用してユーザー情報エンドポイントから取得する必要があります。 IdentityModelライブラリーのヘルパーAPIを使用して、ユーザー情報エンドポイントに簡単にアクセスできます。私たちのサンプルはあなたがこれを行う方法を示しています:https://github.com/IdentityServer/IdentityServer3.Samples/blob/master/source/Clients/MVC%20OWIN%20Client%20(Hybrid)/Startup.cs#L66

+0

こんにちは@Brockアレン、ありがとう。好奇心の外に私は 'testScope'という名前のカスタムスコープを追加し、ClaimsプロパティはListに設定されている { new ScopeClaim(IdentityServer3.Core.Constants.ClaimTypes.GivenName、alwaysInclude:true) }まだ見ることができません私の例では 'given_name'です。 OpenIdConnectAuthenticationOptionsでは、Hybridフローにこれらのオプションが必要であるため、ResponseTypeの値を 'code id_token'に設定しました。 – user2243747

+0

「アイデンティティ」としてスコープのタイプを変更しました。私はクレームのGivenNameを見ることができました。 ScopeType.ResourceとScopeType.Identityの違いを理解する必要があります – user2243747

関連する問題