All files / simple-oauth2/lib encoding.js

100% Statements 5/5
100% Branches 0/0
100% Functions 0/0
100% Lines 5/5

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    1x   1x   34x                   17x   17x      
'use strict';
 
const HEADER_ENCODING_FORMAT = 'base64';
 
module.exports = {
  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);
  },
};