Javascript JWT Simple Server client library
Home Repository:
https://github.com/Xabaril/JWTSimpleServer
The typescript library will allow you to easily interact will the token endpoint.
Follow this steps to create your client if you are using the browser bundled library:
1. Create the client options
var defaultServerOptions = ;
Client options parameters have default values listed in this table:
Parameter | default value |
---|---|
tokenEndpoint | "/token" |
host | window.location.origin |
httpClient | XMLHttpRequestClient |
NOTE: You can implement your own HttpClient by implementing our HttpClient abstract class
2. Creat the client providing the options object:
var simpleServerClient = defaultServerOptions;
- Request an access token by executing requestAccessToken method:
simpleServerClient :
*Client events
JWT client have several observables you can subscribe to:
Observable | return value | description |
---|---|---|
onBeforeRequestAccessToken | void | Will notify observers before starting the token request to the server |
onRequestAccessTokenSuccess | Token | Will notify observers passing the retrieved token as parameter |
onBeforeRequestRefreshToken | void | Will notify observers before starting the refresh token request to the server |
onRequestRefreshTokenSuccess | Token | Will notify observers passing the retrieved refresh token as parameter |
4. Optional: If you want the library to request new access tokens given an interval you can configure the RefreshTokenService
var refreshService = simpleServerClient; let { console;} //Start the renewal servicerefreshServicestart intervalSeconds: 10 refreshToken onRefreshTokenSuccessCallback: onTokenRefreshedFunction; //Stop the renewal servicerefreshService;