2016-05-27 8 views
0

は、私がOAuth 2.0Open Id Connectを学んだし、今私は問題を抱えていると主張:私は彼のためにInMemoryUserおよび特許請求の範囲を作成しているのOAuth 2.0とオープンIdを接続するには、問題

return new List<InMemoryUser>() 
{ 
    new InMemoryUser() 
    { 
     Username = "SomeName", 
     Password = "SomePassword", 
     Subject = "b05d3546-6ca8-4d32-b95c-77e94d705ddf", 
     Claims = new Claim[] 
     { 
      new Claim(IdentityServer3.Core.Constants.ClaimTypes.GivenName, "MyGivenName"), 
      new Claim(IdentityServer3.Core.Constants.ClaimTypes.FamilyName, "MyFamilyName"), 

     } 
    } 
} 
id_tokenで提示クレームが存在しません

マイスコープ:

return new List<Scope>() 
{ 
    StandardScopes.OpenId, 
    StandardScopes.Profile, 

    new Scope() 
    { 
     Name = "somename", 
     DisplayName = "some display name", 
     Description = "some description", 
     Type = ScopeType.Resource 
    } 
}; 

また、私が作成したMVCクライアントとStartupクラスやでcludedプロフィールscope

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

    app.UseOpenIdConnectAuthentication(new OpenIdConnectAuthenticationOptions() 
    { 
     ClientId = "TripsHybrid", 
     Authority = Constants.Constants.TripsSts, 
     RedirectUri = Constants.Constants.TripsMvc, 
     SignInAsAuthenticationType = "Cookies", 
     ResponseType = "code id_token token", 
     Scope = "openid profile", // "profile" scope inсluded 
    } 
} 

しかし、私はid_tokenを取得し、それをデコードしたときに、私のInMemoryUserの作成中に、私が設定したクレームが存在しません。また、クレームがDebugにそれらを印刷した後User.Identity.Claimsではありません。

if (this.User.Identity.IsAuthenticated) 
{ 
    Debug.WriteLine("Claims:"); 
    var identity = this.User.Identity as ClaimsIdentity; 
    foreach (var claim in identity.Claims) 
    { 
     Debug.WriteLine(claim.Type + " - " + claim.Value); 
    } 
} 

してください、その理由を見つけて、id_tokenにクレームを追加するために私を助けて。おかげ

答えて

0

最後に、私は問題の解決策を見つけました。

問題がありましたIdentityServer3 NuGetパッケージのバージョンです。チュートリアルではパッケージIdentityServer3 2.0.1が使用されましたが、パッケージIdentityServer3 2.5.0がインストールされています。

私はスコープを得るとき、私は自分のコードを変更しました:

public static IEnumerable<Scope> Get() 
{ 
    Scope profileScope = StandardScopes.Profile; 
    profileScope.IncludeAllClaimsForUser = true; // set this property to true 

    return new List<Scope>() 
    { 
     StandardScopes.OpenId, 
     profileScope, 

     new Scope() 
     { 
      Name = "somename", 
      DisplayName = "some display name", 
      Description = "some description", 
      Type = ScopeType.Resource 
     } 
    }; 
} 

私はIncludeAllClaimsForUser = trueを設定しているし、今すべての請求は、IDトークン(id_token)中に存在していると、私はこれを使用して、私のMVCのクライアントのすべての主張を得ることができますコード(前回と同じ):

私は予想通り、私の問題のコードは、働いていた古いパッケージを使用しようとした
if (this.User.Identity.IsAuthenticated) 
{ 
    Debug.WriteLine("Claims:"); 
    var identity = this.User.Identity as ClaimsIdentity; 
    foreach (var claim in identity.Claims) 
    { 
     Debug.WriteLine(claim.Type + " - " + claim.Value); 
    } 
} 

(変更なし)。

IdentityServer3の新しいバージョンでは、このプロパティのデフォルト値がfalseに変更されたようです。

ありがとうございます。

1

私のために[OK]すべてのもののsamesなく、請求項に起因identityserverとaspNetIdentity

でクレーム間のdiffrenceに正しくマッピングされなかったいくつかの時間があなたのMVCアプリStartup.csのデフォルトのクレームのマッピングを消去してみてください:

// Clear The InboundClaimTypeMap 
     JwtSecurityTokenHandler.InboundClaimTypeMap.Clear(); 
+0

それは役に立たなかった。 IDトークンにクレームがありません –

関連する問題