Tumortisch-Dist/resources/app/node_modules/simple-oauth2/lib/encoding.js

30 lines
889 B
JavaScript
Raw Permalink Normal View History

2021-06-15 16:00:08 +02:00
'use strict';
const HEADER_ENCODING_FORMAT = 'base64';
module.exports = {
/**
* Encode a single {value} using the application/x-www-form-urlencoded media type
* while also applying some additional rules specified by the spec
*
* @see https://tools.ietf.org/html/rfc6749#appendix-B
*
* @param {String} value
*/
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);
},
};