イントロスペクションで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);
}
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です。