UNPKG

@sovrano-io/auth-sdk

Version:

Sovrano wallet auth sdk for koinos dapps

69 lines 1.74 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.Authorizer = void 0; const utils_1 = require("./utils"); const config_1 = require("./config"); class Authorizer { /** * Get the URL to redirect to for authorization * @param data * @returns */ static getRequestUrl(data) { const encodedData = this.encodeRequest(data); return `${(0, config_1.getConfig)().baseUrl}/authorize?data=${encodedData}`; } /** * Get the URL to redirect to after authorization * * @param data * @param url * @returns */ static getResponseUrl(data, url) { const encodedData = this.encodeResponse(data); return `${url}?data=${encodedData}`; } /** * Encode the request data * @param data * @returns */ static encodeRequest(data) { return (0, utils_1.encodeParams)(data); } /** * Decode the request data * @param data * @returns */ static decodeRequest(data) { return (0, utils_1.decodeParams)(data); } /** * Encode the response data * @returns */ static encodeResponse(data) { return (0, utils_1.encodeParams)(data); } /** * Decode the response data * @param data * @returns */ static decodeResponse(data) { return (0, utils_1.decodeParams)(data); } /** * Get the response data from the URL * @returns */ static getResponse(responseUrl) { const url = new URL(responseUrl); const data = url.searchParams.get('data'); return this.decodeResponse(data); } } exports.Authorizer = Authorizer; //# sourceMappingURL=Authorizer.js.map