@okta-dfuhriman/okta-auth-js
Version:
The Okta Auth SDK
63 lines (59 loc) • 3.99 kB
JavaScript
/*!
* 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.
*/
import { genRandomString } from '../../util/misc.js';
import { removeTrailingSlash } from '../../util/url.js';
import AuthSdkError from '../../errors/AuthSdkError.js';
function generateState() {
return genRandomString(64);
}
function generateNonce() {
return genRandomString(64);
}
function getIssuer(sdk, options = {}) {
const issuer = 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) {
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s;
if (arguments.length > 2) {
throw new AuthSdkError('As of version 3.0, "getOAuthUrls" takes only a single set of options');
}
const baseUrl = getOAuthBaseUrl(sdk, options);
const authorizeUrl = (_c = (_a = removeTrailingSlash(options === null || options === void 0 ? void 0 : options.authorizeUrl)) !== null && _a !== void 0 ? _a : (_b = sdk === null || sdk === void 0 ? void 0 : sdk.options) === null || _b === void 0 ? void 0 : _b.authorizeUrl) !== null && _c !== void 0 ? _c : baseUrl + '/v1/authorize';
const issuer = getIssuer(sdk, options);
const userinfoUrl = (_f = (_d = removeTrailingSlash(options === null || options === void 0 ? void 0 : options.userinfoUrl)) !== null && _d !== void 0 ? _d : (_e = sdk === null || sdk === void 0 ? void 0 : sdk.options) === null || _e === void 0 ? void 0 : _e.userinfoUrl) !== null && _f !== void 0 ? _f : baseUrl + '/v1/userinfo';
const tokenUrl = (_j = (_g = removeTrailingSlash(options === null || options === void 0 ? void 0 : options.tokenUrl)) !== null && _g !== void 0 ? _g : (_h = sdk === null || sdk === void 0 ? void 0 : sdk.options) === null || _h === void 0 ? void 0 : _h.tokenUrl) !== null && _j !== void 0 ? _j : baseUrl + '/v1/token';
const logoutUrl = (_m = (_k = removeTrailingSlash(options === null || options === void 0 ? void 0 : options.logoutUrl)) !== null && _k !== void 0 ? _k : (_l = sdk === null || sdk === void 0 ? void 0 : sdk.options) === null || _l === void 0 ? void 0 : _l.logoutUrl) !== null && _m !== void 0 ? _m : baseUrl + '/v1/logout';
const revokeUrl = (_q = (_o = removeTrailingSlash(options === null || options === void 0 ? void 0 : options.revokeUrl)) !== null && _o !== void 0 ? _o : (_p = sdk === null || sdk === void 0 ? void 0 : sdk.options) === null || _p === void 0 ? void 0 : _p.revokeUrl) !== null && _q !== void 0 ? _q : baseUrl + '/v1/revoke';
const pushAuthorizationUrl = (_r = removeTrailingSlash(options === null || options === void 0 ? void 0 : options.pushAuthorizationUrl)) !== null && _r !== void 0 ? _r : (_s = sdk === null || sdk === void 0 ? void 0 : sdk.options) === null || _s === void 0 ? void 0 : _s.pushAuthorizationUrl;
return {
issuer,
authorizeUrl,
userinfoUrl,
tokenUrl,
revokeUrl,
logoutUrl,
pushAuthorizationUrl
};
}
export { generateNonce, generateState, getOAuthBaseUrl, getOAuthDomain, getOAuthUrls };
//# sourceMappingURL=oauth.js.map