oauth 2.0 - Make the User.Identity include the email address from the access token payload -
we using oauth via introspection validate access tokens.
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"; });
this works, mostly.
the authorization server response @ connect/introspect
good.
{ "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": "shaun@bigfont.ca", "aspnet.identity.securitystamp": "4956a5c3-9efd-4f51-9746-43a187698e1e" }
a request resource server gets past authorize
attribute. good.
[authorize(activeauthenticationschemes = oauthvalidationdefaults.authenticationscheme)] [httpget("message")] public iactionresult getmessage() { var identity = user.identity claimsidentity; if (identity == null) { return badrequest(); } return json(user); }
the user
though, not contain sub
nor email
properties. looks this:
{ "claims": [ { "issuer": "local authority", "originalissuer": "local authority", "properties": {}, "subject": { "authenticationtype": "bearer", "isauthenticated": true, "actor": null, "bootstrapcontext": null, "claims": [] } } ] }
how can configure our resource server include sub
, email
properties in claims?
here our code on github.
the claims there (if they're not, it's bug in introspection middleware), json.net not @ serializing claim
/claimsidentity
/claimsprincipal
, because these types have circular references (e.g claim.subject
/ claimsidentity.claims
).
try using user.findfirst(claimtypes.nameidentifier)?.value
, user.findfirst(claimtypes.email)?.value
/ confirm subject identifier , email address there.
if works, consider returning projection of claims instead of claimsprincipal
instance:
return json( claim in user.claims select new { claim.type, claim.value } );
here screenshot user
in debug window.
Comments
Post a Comment