1
我遵循Using OAuth to Secure Your ASP.NET API課程Pluralsight。我已經建立了IdentityServer與多家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
}
},
};
}
如果我授權用戶,並使用附帶的訪問令牌來調用API,權利要求書的收集,爲用戶,看起來像這樣...
((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}
如果我放棄,我使用到調試器在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"
]
}
我不清楚是什麼這是我做或不做,即停止從返回中定義的聲明。
任何想法?
我添加了該配置方法的最頂端IdentityServer項目中的啓動類,但無濟於事。逐句通過我的代碼我注意到,我期望的聲明都在集合中,當我處理用戶服務中的AuthenticateLocalAsync方法時(自發布原始問題以來,我已經從InMemoryUsers中移除) –
將它添加到在我的** API **項目中啓動類的配置方法的頂部,它的工作! –