@okta/configuration-validation
Version:
Configuration validation support for Okta JavaScript SDKs
28 lines (25 loc) • 4.38 kB
JavaScript
/*! *****************************************************************************
Copyright (c) Microsoft Corporation.
Permission to use, copy, modify, and/or distribute this software for any
purpose with or without fee is hereby granted.
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
PERFORMANCE OF THIS SOFTWARE.
***************************************************************************** */
var t=function(e,o){return(t=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var o in e)Object.prototype.hasOwnProperty.call(e,o)&&(t[o]=e[o])})(e,o)};
/*!
* Copyright (c) 2018-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.
*/
var e=function(e){function o(){return null!==e&&e.apply(this,arguments)||this}return function(e,o){function i(){this.constructor=e}t(e,o),e.prototype=null===o?Object.create(o):(i.prototype=o.prototype,new i)}(o,e),o}(Error),o="You can copy it from the Okta Developer Console in the details for the Application you created. Follow these instructions to find it: https://bit.ly/finding-okta-app-credentials",i=new RegExp("^https://"),n=new RegExp("://"),r=/-admin.(okta|oktapreview|okta-emea).com/,a=new RegExp("/$"),c=function(t){var e=(t=t||{}).scopes;!e&&t.scope&&(e=Array.isArray(t.scope)?t.scope:t.scope.split(/\s+/));var o=t.tokenManager,i=void 0!==t.autoRenew?t.autoRenew:t.auto_renew,n=t.storage;void 0===n&&void 0===i||(o=Object.assign({autoRenew:i,storage:n},o||{}));var r=t.responseType||t.response_type;return"string"==typeof r&&r.indexOf(" ")>=0&&(r=r.split(/\s+/)),Object.assign({},t,{clientId:t.clientId||t.client_id,redirectUri:t.redirectUri||t.redirect_uri,responseType:r,scopes:e,tokenManager:o})},s=function(t,o){void 0===o&&(o={});var n="You can copy your domain from the Okta Developer Console. Follow these instructions to find it: https://bit.ly/finding-okta-domain";if(o.disableHttpsCheck){console.warn("Warning: HTTPS check is disabled. This allows for insecure configurations and is NOT recommended for production use.")}if(!t)throw new e("Your Okta URL is missing. "+n);if(!o.disableHttpsCheck&&!t.match(i))throw new e("Your Okta URL must start with https. Current value: "+t+". "+n);if(t.match(/{yourOktaDomain}/))throw new e("Replace {yourOktaDomain} with your Okta domain. "+n);if(t.match(r))throw new e("Your Okta domain should not contain -admin. Current value: "+t+". "+n)},p=function(t){if(!t)throw new e("Your client ID is missing. "+o);if(t.match(/{clientId}/))throw new e("Replace {clientId} with the client ID of your Application. "+o)},u=function(t){if(!t)throw new e("Your client secret is missing. "+o);if(t.match(/{clientSecret}/))throw new e("Replace {clientSecret} with the client secret of your Application. "+o)},l=function(t){if(!t)throw new e("Your redirect URI is missing.");if(t.match(/{redirectUri}/))throw new e("Replace {redirectUri} with the redirect URI of your Application.")},h=function(t){if(!t)throw new e("Your appBaseUrl is missing.");if(t.match(/{appBaseUrl}/))throw new e("Replace {appBaseUrl} with the base URL of your Application.");if(!t.match(n))throw new e("Your appBaseUrl must contain a protocol (e.g. https://). Current value: "+t+".");if(t.match(a))throw new e("Your appBaseUrl must not end in a '/'. Current value: "+t+".")};export{h as assertAppBaseUrl,p as assertClientId,u as assertClientSecret,s as assertIssuer,l as assertRedirectUri,c as buildConfigObject};