MCPcopy Create free account
hub / github.com/ampproject/amphtml / decodeInternal_

Method decodeInternal_

third_party/subscriptions-project/swg.js:4184–4208  ·  view source on GitHub ↗

* @param {string} encodedToken * @return {!JwtTokenInternalDef} * @private

(encodedToken)

Source from the content-addressed store, hash-verified

4182 * @private
4183 */
4184 decodeInternal_(encodedToken) {
4185 // See https://jwt.io/introduction/
4186 /**
4187 * Throws error about invalid token.
4188 */
4189 function invalidToken() {
4190 throw new Error(`Invalid token: "${encodedToken}"`);
4191 }
4192
4193 // Encoded token has three parts: header.payload.sig
4194 // Note! The padding is not allowed by JWT spec:
4195 // http://self-issued.info/docs/draft-goland-json-web-token-00.html#rfc.section.5
4196 const parts = encodedToken.split('.');
4197 if (parts.length != 3) {
4198 invalidToken();
4199 }
4200 const headerUtf8Bytes = base64UrlDecodeToBytes(parts[0]);
4201 const payloadUtf8Bytes = base64UrlDecodeToBytes(parts[1]);
4202 return {
4203 header: tryParseJson(utf8DecodeSync(headerUtf8Bytes), invalidToken),
4204 payload: tryParseJson(utf8DecodeSync(payloadUtf8Bytes), invalidToken),
4205 verifiable: `${parts[0]}.${parts[1]}`,
4206 sig: parts[2],
4207 };
4208 }
4209}
4210
4211/**

Callers 1

decodeMethod · 0.95

Calls 3

base64UrlDecodeToBytesFunction · 0.70
tryParseJsonFunction · 0.70
utf8DecodeSyncFunction · 0.70

Tested by

no test coverage detected