2016-07-19 6 views
1

Using OAuth to Secure Your ASP.NET APIコースをPluralsightにフォローしています。私は、ユーザーを承認し、APIを呼び出すために供給されたアクセストークンを使用している場合、私はそのために、...このようになります。そのうちの一つ、InMemoryUsersの数と主張コレクションをIdentityServer3の申し立てを取得する

public static List<InMemoryUser> Get() 
{ 
    return new List<InMemoryUser> 
     { 
      new InMemoryUser 
      { 
       Username = "[email protected]", 
       Password = "password", 
       Subject = "[email protected]", 
       Claims = new[] 
         { 
          new Claim(Constants.ClaimTypes.Id, "96cddc1de66641829237b7f09869b1c8"), 
          new Claim(Constants.ClaimTypes.Name, "Some Full name example 
         } 
      }, 
     }; 
} 

をIdentityServerを設定していますユーザーは、私は私がこれを取得jwt.ioでデバッガに使用しているアクセスキー...

{ 
    "iss": "https://localhost:44375", 
    "aud": "https://localhost:44375/resources", 
    "exp": 1468921471, 
    "nbf": 1468917871, 
    "client_id": "my_clientid, 
    "scope": "openid", 
    "sub": "[email protected]", 
    "auth_time": 1468917871, 
    "idp": "idsrv", 
    "amr": [ 
    "password" 
    ] 
} 

をドロップすると、私は不明だ

((User as System.Security.Claims.ClaimsPrincipal).Identities.First() as System.Security.Claims.ClaimsIdentity).Claims.ToList() 
Count = 10 
    [0]: {iss: https://localhost:44375} 
    [1]: {aud: https://localhost:44375/resources} 
    [2]: {exp: 1468920204} 
    [3]: {nbf: 1468916604} 
    [4]: {client_id: my_clientid} 
    [5]: {scope: openid} 
    [6]: {http://schemas.xmlsoap.org/ws/2005/05/identity/claims/nameidentifier: [email protected]} 
    [7]: {http://schemas.microsoft.com/ws/2008/06/identity/claims/authenticationinstant: 1468916604} 
    [8]: {http://schemas.microsoft.com/identity/claims/identityprovider: idsrv} 
    [9]: {http://schemas.microsoft.com/claims/authnmethodsreferences: password} 

...このように見えるものそれは私ですそれは返されることから定義されたクレームを停止することです。

アイデア?

答えて

4

MicrosoftのJWTトークンハンドラのデフォルトの動作になります。

マイクロソフトでは、どのようなクレームタイプがあなたにとって最適であるかを知っていると考えています。

あなたはそれを受け入れることができますどちらか - または(例えば起動時に)どこかのコードのこの美しい作品を呼び出すことにより、その動作をオフにします。

JwtSecurityTokenHandler.InboundClaimTypeMap.Clear()

+0

私はその設定方法の最上部に追加しましたIdentityServerプロジェクトのStartupクラスのうちの1つです。私のコードを踏み出す私のユーザサービスで 'AuthenticateLocalAsync'メソッドを扱っているときに、私が期待している要求はすべてコレクションに入っていることに気付きます。(元の質問を投稿してからInMemoryUsersから離れました) –

+0

私の** API **プロジェクトのStartupクラスのConfigurationメソッドの先頭です。 –

関連する問題