UNPKG

@okta-dfuhriman/okta-auth-js

Version:
42 lines (38 loc) 2.06 kB
/*! * 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 { __rest } from '../../_virtual/_tslib.js'; import AuthSdkError from '../../errors/AuthSdkError.js'; import { convertTokenParamsToOAuthParams } from './authorize.js'; import { httpRequest } from '../../http/request.js'; import 'tiny-emitter'; import 'js-cookie'; import 'cross-fetch'; async function postToParEndpoint(sdk, tokenParams) { const _a = tokenParams || {}, { jwtAuthorizationRequest = false, pushAuthorizationUrl: url, extraParams } = _a, options = __rest(_a, ["jwtAuthorizationRequest", "pushAuthorizationUrl", "extraParams"]); const data = convertTokenParamsToOAuthParams(options); const headers = { 'Content-Type': 'application/x-www-form-urlencoded', }; if (!url) { throw new AuthSdkError('In order to use push authorization request, a valid URL must be specified in the OktaAuth constructor that will generate the push authorization and return the appropriate response.'); } const now = Math.floor(Date.now() / 1000); const { client_assertion: clientAssertion, expires_in: expiresIn, request_uri: requestUri } = await httpRequest(sdk, { url, method: 'POST', args: Object.assign(Object.assign({ 'jwt_authorization_request': jwtAuthorizationRequest }, extraParams), data), headers, }); return { clientAssertion, expiresAt: expiresIn + now, requestUri }; } export { postToParEndpoint }; //# sourceMappingURL=par.js.map