1 | import AuthRequestBuilder from "@lonelyplanet/open-planet-node/dist/authRequestBuilder";
|
2 | import TYPES from "../types";
|
3 | import {
|
4 | IAuthOptionsDefaults,
|
5 | IAuthRequestParams,
|
6 | } from "../interfaces";
|
7 | import { authDefaults } from "../constants";
|
8 |
|
9 | export 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 |
|
26 | export default {
|
27 | authSetupWithDefaults,
|
28 | };
|