src/client.js
/**
   * Request an access token from a remote server
   * @param {*} server The base url of the server to request a token from
   * @param {*} kid the identifier of the key to use for signing the token request
   * @param {*} scopes the scopes to request access for
   */
Request an access token from a remote server
@param {*} server The base url of the server to request a token from
@param {*} kid the identifier of the key to use for signing the token request
@param {*} scopes the scopes to request access for
Request an access token from a remote server @param { * } server The base url of the server to request a token from @param { * } kid the identifier of the key to use for signing the token request @param { * } scopes the scopes to request access for
async requestAccessToken(server, kid = this.signingKeyId, scopes = this.scopes()) {
    let accessToken = await this.getAccessToken(server)
    if (accessToken && (accessToken.issued_at + accessToken.expires_in) > (Date.now() / 1000)) {
      return accessToken;
    }
    let serverConfig = this.persistence.getServerConfiguration(server)
    let client = this.persistence.getClientConfiguration(server)
    if (!client && serverConfig.registration_endpoint) {
      client = await this.register(server);
    }
    if (client) {
      let jwt = await this.generateJWT(client.client_id, serverConfig.token_endpoint, kid)
      let params = {
        client_assertion: jwt,
        client_assertion_type: '',
        grant_type: 'client_credentials',
        scopes: scopes
      }
      const config = {
        headers: {
          'Content-Type': 'application/x-www-form-urlencoded'
        }
      }
      let response = await axios.post(serverConfig.token_endpoint, qs.stringify(params), config)
      let token = response.data
      token.issued_at = Date.now() / 1000
      await this.addAccessToken(server, token)
      return token
    }
    else {
      throw "Client information not found"
    }
  }
async requestAccessToken ( server , kid = this . signingKeyId , scopes = this . scopes ( ) ) { let accessToken = await this . getAccessToken ( server ) if ( accessToken && ( accessToken . issued_at + accessToken . expires_in ) > ( Date . now ( ) / 1000 ) ) { return accessToken ; } let serverConfig = this . persistence . getServerConfiguration ( server ) let client = this . persistence . getClientConfiguration ( server ) if ( ! client && serverConfig . registration_endpoint ) { client = await this . register ( server ) ; } if ( client ) { let jwt = await this . generateJWT ( client . client_id , serverConfig . token_endpoint , kid ) let params = { client_assertion : jwt , client_assertion_type : '' , grant_type : 'client_credentials' , scopes : scopes } const config = { headers : { 'Content-Type' : 'application/x-www-form-urlencoded' } } let response = await axios . post ( serverConfig . token_endpoint , qs . stringify ( params ) , config ) let token = response . data token . issued_at = Date . now ( ) / 1000 await this . addAccessToken ( server , token ) return token } else { throw "Client information not found" } }
Request an access token from a remote server
 @param {*} server The base url of the server to request a token from
 @param {*} kid the identifier of the key to use for signing the token request
 @param {*} scopes the scopes to request access for
Request an access token from a remote server @param { * } server The base url of the server to request a token from @param { * } kid the identifier of the key to use for signing the token request @param { * } scopes the scopes to request access for
// see if there is an access token that is still good and send that back if so //If the client configuration does not exist try to self register the client // if the client configuration exists try to get an access token 