asp.net core - User.Claims is null after deploying application while users are still logged in -
i have aspnet core web application uses identity claims (w/ jwt token authorization). have expiration token set 2 days.
the normal process of logging in, authenticating credentials, , receiving / sending tokens works well.
the problem i'm having when deploy application iis , users still logged in, user.claims property null. user object has no value. gets refreshed if log out , log in.
the idea can think of detecting if claims null , redirecting login, isn't ideal may continuing update information day before, have fail on submission.
edit (code sample):
applicationuser appuser = _usermanager.findbynameasync(login).result; var displayname = appuser.todisplayname(); var claimsidentity = new claimsidentity(userclaims, "bearer"); claimsidentity.addclaim(new claim("displayname", displayname)); await _usermanager.addclaimasync(appuser, new claim("id", appuser.id)); // server claim await _usermanager.addclaimasync(appuser, new claim("displayname", displayname)); // server claim await _usermanager.updateasync(appuser); // return token client. var expires = datetime.utcnow.addminutes(2880); var token = getjwttoken(expires, claimsidentity); return new tokendto() { id_token = token, tokenexpires = expires, displayname = displayname, authenticated = true, username = appuser.username, roles = applicationroles // roles client-side nav authorization };
getjwttoken
private string getjwttoken(datetime? expires, claimsidentity identity) { var handler = new jwtsecuritytokenhandler(); var securitytoken = handler.createtoken(new securitytokendescriptor() { issuer = _tokenoptions.issuer, audience = _tokenoptions.audience, signingcredentials = _tokenoptions.signingcredentials, subject = identity, expires = expires, notbefore = datetime.utcnow.addminutes(-1) }); return handler.writetoken(securitytoken); }
calling user.claims:
[httpput] public iactionresult put([frombody]orderprocessupdatedto orderprocessupdatedto) { // claims null here var currentuserid = user.claims.single(x => x.type == nameof(customclaimtype.id)).value; ... }
wiki
Comments
Post a Comment