dsuryd / dotNetify

Simple, lightweight, yet powerful way to build real-time web apps.
https://dotnetify.net
Other
1.17k stars 164 forks source link

Update JWT token #251

Closed Sigve84 closed 4 years ago

Sigve84 commented 4 years ago

I am using JWT auth. The JWT has a TTL of 5 mins, so I need to update the JWT token at regular intervals. At the moment I am setting this in the header part of dotnetify.react.connect. I am fetching a new JWT from the auth provder at regular intervals before it will expire, but how do I update the header to use for authorization from react?

this.vm = dotnetify.react.connect("vm", this, { headers: Auth.getAuthHeader(), });

dsuryd commented 4 years ago

Try this: vm.dispatch({$headers: "<new token>"})

Sigve84 commented 4 years ago

Tried it, and it do not seem to work. principal = ValidateBearerToken(ParseHeaders(hubContext.Headers), out validatedToken); still validates the old JWT token

dsuryd commented 4 years ago

There was a bug in the extract headers middleware which is now fixed in the repo. This will be how a client can update the token in the headers:

this.vm.$dispatch({ $headers: { Authorization: 'Bearer ' + jwt.access_token }})