Мы используем OAuth через интроспекцию для проверки токенов доступа.Сделать User.Identity включен адрес электронной почты из полезной нагрузки токена доступа
app.UseOAuthIntrospection(options =>
{
options.AutomaticAuthenticate = true;
options.AutomaticChallenge = true;
options.Authority = "http://localhost:12345/";
options.Audiences.Add("ResourceServer01");
options.ClientId = "ResourceServer01";
options.ClientSecret = "secret_secret_secret";
});
Это работает, в основном.
Ответ сервера авторизации на connect/introspect
является хорошим.
{
"active": true,
"iss": "http://localhost:12345/",
"sub": "797264b3-194c-483f-08fb-08d3cbab9158",
"scope": "openid email roles",
"iat": 1471998289,
"nbf": 1471998289,
"exp": 1472000089,
"jti": "274cbb7f-9412-4d69-8c02-ca6a500b4a36",
"token_type": "Bearer",
"aud": [
"ResourceServer01",
"ResourceServer02"
],
"email": "[email protected]",
"AspNet.Identity.SecurityStamp": "4956a5c3-9efd-4f51-9746-43a187698e1e"
}
Запрос на сервер ресурсов проходит мимо атрибута Authorize
. Это тоже хорошо.
[Authorize(ActiveAuthenticationSchemes = OAuthValidationDefaults.AuthenticationScheme)]
[HttpGet("message")]
public IActionResult GetMessage() {
var identity = User.Identity as ClaimsIdentity;
if (identity == null) {
return BadRequest();
}
return Json(User);
}
The User
однако, не содержит sub
, ни email
свойства. Это выглядит примерно так:
{
"claims": [
{
"issuer": "LOCAL AUTHORITY",
"originalIssuer": "LOCAL AUTHORITY",
"properties": {},
"subject": {
"authenticationType": "Bearer",
"isAuthenticated": true,
"actor": null,
"bootstrapContext": null,
"claims": []
}
}
]
}
Как мы можем настроить наш сервер ресурсов включить sub
и email
свойства в формуле?
Адрес our code on GitHub.