All files / simple-oauth2/lib encoding.js

100% Statements 10/10
100% Branches 4/4
100% Functions 3/3
100% Lines 10/10

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38    6x   6x   42x 34x     8x 5x         3x           62x                   31x   31x      
'use strict';
 
const HEADER_ENCODING_FORMAT = 'base64';
 
module.exports = {
  getScopeParam(scope) {
    if (scope === undefined) {
      return null;
    }
 
    if (Array.isArray(scope)) {
      return {
        scope: scope.join(' '),
      };
    }
 
    return {
      scope,
    };
  },
 
  useFormURLEncode(value) {
    return encodeURIComponent(value).replace(/%20/g, '+');
  },
 
  /**
   * Get the authorization header used to request a valid token
   * @param  {String} clientID
   * @param  {String} clientSecret
   * @return {String}              Authorization header string token
   */
  getAuthorizationHeaderToken(clientID, clientSecret) {
    const encodedCredentials = `${this.useFormURLEncode(clientID)}:${this.useFormURLEncode(clientSecret)}`;
 
    return Buffer.from(encodedCredentials).toString(HEADER_ENCODING_FORMAT);
  },
};