UNPKG

@okta-dfuhriman/okta-auth-js

Version:
69 lines (66 loc) 2.96 kB
"use strict"; var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault"); exports.generateNonce = generateNonce; exports.generateState = generateState; exports.getOAuthBaseUrl = getOAuthBaseUrl; exports.getOAuthDomain = getOAuthDomain; exports.getOAuthUrls = getOAuthUrls; var _util = require("../../util"); var _AuthSdkError = _interopRequireDefault(require("../../errors/AuthSdkError")); /*! * Copyright (c) 2015-present, Okta, Inc. and/or its affiliates. All rights reserved. * The Okta software accompanied by this notice is provided pursuant to the Apache License, Version 2.0 (the "License.") * * You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0. * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * * See the License for the specific language governing permissions and limitations under the License. * */ /* eslint-disable complexity, max-statements */ function generateState() { return (0, _util.genRandomString)(64); } function generateNonce() { return (0, _util.genRandomString)(64); } function getIssuer(sdk, options = {}) { const issuer = (0, _util.removeTrailingSlash)(options.issuer) || sdk.options.issuer; return issuer; } function getOAuthBaseUrl(sdk, options = {}) { const issuer = getIssuer(sdk, options); const baseUrl = issuer.indexOf('/oauth2') > 0 ? issuer : issuer + '/oauth2'; return baseUrl; } function getOAuthDomain(sdk, options = {}) { const issuer = getIssuer(sdk, options); const domain = issuer.split('/oauth2')[0]; return domain; } function getOAuthUrls(sdk, options) { if (arguments.length > 2) { throw new _AuthSdkError.default('As of version 3.0, "getOAuthUrls" takes only a single set of options'); } const baseUrl = getOAuthBaseUrl(sdk, options); // Get user-supplied arguments const authorizeUrl = (0, _util.removeTrailingSlash)(options?.authorizeUrl) ?? sdk?.options?.authorizeUrl ?? baseUrl + '/v1/authorize'; const issuer = getIssuer(sdk, options); const userinfoUrl = (0, _util.removeTrailingSlash)(options?.userinfoUrl) ?? sdk?.options?.userinfoUrl ?? baseUrl + '/v1/userinfo'; const tokenUrl = (0, _util.removeTrailingSlash)(options?.tokenUrl) ?? sdk?.options?.tokenUrl ?? baseUrl + '/v1/token'; const logoutUrl = (0, _util.removeTrailingSlash)(options?.logoutUrl) ?? sdk?.options?.logoutUrl ?? baseUrl + '/v1/logout'; const revokeUrl = (0, _util.removeTrailingSlash)(options?.revokeUrl) ?? sdk?.options?.revokeUrl ?? baseUrl + '/v1/revoke'; const pushAuthorizationUrl = (0, _util.removeTrailingSlash)(options?.pushAuthorizationUrl) ?? sdk?.options?.pushAuthorizationUrl; return { issuer, authorizeUrl, userinfoUrl, tokenUrl, revokeUrl, logoutUrl, pushAuthorizationUrl }; } //# sourceMappingURL=oauth.js.map