UNPKG

@obelisk/client

Version:

Typescript client to interact with Obelisk on a higher level than the regular ReST API calls.

43 lines (42 loc) 1.55 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.TokenResponse = void 0; /** * @hidden */ class TokenResponse { constructor(url, flow) { const u = new URL(url).hash.substr(1); if (u.length === 0) { throw new Error('No fragment'); } const tokResp = {}; u.split('&').map(str => str.split('=')).forEach(([key, val]) => { tokResp[key] = val; }); this.access_token = tokResp.access_token; this.code = tokResp.code; this.expires_in = tokResp.expires_in; this.id_token = tokResp.id_token; this["not-before-policy"] = tokResp["not-before-policy"]; this.refresh_token = tokResp.refresh_token; this.refresh_expires_in = tokResp.refresh_expires_in; this.scope = tokResp.scope; this.session_state = tokResp.session_state; this.state = tokResp.state; this.token_type = tokResp.token_type; let requiredPropsPresent; switch (flow) { case 'implicit': requiredPropsPresent = this.access_token !== undefined && this.id_token !== undefined && this.session_state !== undefined; break; case 'standard': requiredPropsPresent = this.code !== undefined; break; } if (!requiredPropsPresent) { throw new Error('Fragment is not a TokenResponse'); } } } exports.TokenResponse = TokenResponse;