UNPKG

917 BPlain TextView Raw
1import AuthRequestBuilder from "@lonelyplanet/open-planet-node/dist/authRequestBuilder";
2import TYPES from "../types";
3import {
4 IAuthOptionsDefaults,
5 IAuthRequestParams,
6} from "../interfaces";
7import { authDefaults } from "../constants";
8
9export const authSetupWithDefaults = (params: IAuthRequestParams = {}) => {
10 const defaults = authDefaults;
11 const options = params.options || {};
12 const host = params.host || defaults.host;
13 return AuthRequestBuilder.build({
14 host: host,
15 options: {
16 ...options,
17 clientId: options.clientId || defaults.options.clientId,
18 scope: options.scope || defaults.options.scope,
19 redirectUri: options.redirectUri || `${host.replace(/http:/, "https:")}/sso`,
20 targetLinkUri: options.targetLinkUri || (typeof window !== "undefined" && window.location.origin + window.location.pathname),
21 }
22 });
23}
24
25
26export default {
27 authSetupWithDefaults,
28};