X-Git-Url: https://git.squeep.com/?a=blobdiff_plain;f=lib%2Fcommunication.js;h=82400c354e2864d5124b605fcaf965169188ecf8;hb=786217e7862a4d956c6510c6a171c86ab160fda6;hp=d52d784690917d503e852309f4256650cfc4c60e;hpb=30851a8cb9f8823b1b395ace8f53d62c5c53abd8;p=squeep-indieauth-helper diff --git a/lib/communication.js b/lib/communication.js index d52d784..82400c3 100644 --- a/lib/communication.js +++ b/lib/communication.js @@ -2,7 +2,6 @@ const axios = require('axios'); const { mf2 } = require('microformats-parser'); -const { base64ToBase64URL } = require('@squeep/base64url'); const { parse: parseLinkHeader } = require('@squeep/web-linking'); const { Iconv } = require('iconv'); const { version: packageVersion, name: packageName } = require('../package.json'); @@ -61,7 +60,7 @@ class Communication { static _challengeFromVerifier(verifier) { const hash = createHash('sha256'); hash.update(verifier); - return base64ToBase64URL(hash.digest('base64')); + return hash.digest('base64url'); } @@ -73,7 +72,7 @@ class Communication { */ /** * Create a code verifier and its challenge. - * @param {Number} length + * @param {Number} length of verifier string, between 43 and 128 * @returns {Promise} */ static async generatePKCE(length = 128) { @@ -83,7 +82,7 @@ class Communication { const bufferLength = Math.floor(length * 3 / 4); const randomBuffer = await randomBytesAsync(bufferLength); - const verifier = base64ToBase64URL(randomBuffer.toString('base64')); + const verifier = randomBuffer.toString('base64url'); const challenge = Communication._challengeFromVerifier(verifier); @@ -219,9 +218,10 @@ class Communication { /** - * Parse and add any header link relations to mf data. + * Parse and add any header link relations from response to microformat data. * @param {Object} microformat * @param {Object} response + * @param {Object} response.headers */ _mergeLinkHeader(microformat, response) { const _scope = _fileScope('_mergeLinkHeader'); @@ -792,15 +792,15 @@ class Communication { /** * Verify a token with an IdP endpoint, using the Authentication header supplied. * @param {URL} introspectionUrlObj - * @param {String} authenticationHeader + * @param {String} authorizationHeader * @param {String} token */ - async introspectToken(introspectionUrlObj, authenticationHeader, token) { + async introspectToken(introspectionUrlObj, authorizationHeader, token) { const _scope = _fileScope('introspectToken'); const formData = common.formData({ token }); const postIntrospectConfig = Communication._axiosConfig('POST', introspectionUrlObj, formData, {}, { - [Enum.Header.Authentication]: authenticationHeader, + [Enum.Header.Authorization]: authorizationHeader, [Enum.Header.ContentType]: Enum.ContentType.ApplicationForm, [Enum.Header.Accept]: `${Enum.ContentType.ApplicationJson}, ${Enum.ContentType.Any};q=0.1`, });