0.0.1 • Published 6 years ago

jwt-simpleserver-client v0.0.1

Weekly downloads
43
License
ISC
Repository
-
Last release
6 years ago

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 = new JwtSimpleServer.ClientOptions();

Client options parameters have default values listed in this table:

Parameterdefault value
tokenEndpoint"/token"
hostwindow.location.origin
httpClientXMLHttpRequestClient

NOTE: You can implement your own HttpClient by implementing our HttpClient abstract class

2. Creat the client providing the options object:

var simpleServerClient =  new JwtSimpleServer.ServerClient(defaultServerOptions);
  1. Request an access token by executing requestAccessToken method:

    simpleServerClient.requestAccessToken({ userName: "demo", password: "demo" })
    	.then(token => {
    	  // your token object will have the access token and expiral, and if configured: the refresh token
       }):

    *Client events

    JWT client have several observables you can subscribe to:

    Observablereturn valuedescription
    onBeforeRequestAccessTokenvoidWill notify observers before starting the token request to the server
    onRequestAccessTokenSuccessTokenWill notify observers passing the retrieved token as parameter
    onBeforeRequestRefreshTokenvoidWill notify observers before starting the refresh token request to the server
    onRequestRefreshTokenSuccessTokenWill 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 = new JwtSimpleServer.RefreshTokenService(simpleServerClient);

let onTokenRefreshedFunction = (token) => {
   console.log("Refresh token service:", token);
}

//Start the renewal service
refreshService.start({
   intervalSeconds: 10,
   refreshToken,
   onRefreshTokenSuccessCallback: onTokenRefreshedFunction
});

//Stop the renewal service
refreshService.stop();