From 9eb9f65a2a4abfa526eafcc2fe2f9fcf59f10c85 Mon Sep 17 00:00:00 2001 From: Warren Parad Date: Sun, 21 Jan 2024 10:22:10 +0100 Subject: [PATCH] Add consistently named property: authressApiUrl. --- README.md | 4 ++-- index.d.ts | 8 +++++++- src/index.js | 6 +++--- tests/index.test.js | 22 +++++++++++----------- 4 files changed, 23 insertions(+), 17 deletions(-) diff --git a/README.md b/README.md index 6326384..8991725 100644 --- a/README.md +++ b/README.md @@ -41,8 +41,8 @@ On every route change check to see if the user exists, and if they don't redirec import { LoginClient } from '@authress/login'; // What is my applicationId => https://authress.io/app/#/manage?focus=applications -// What is my authressLoginHostUrl? => https://authress.io/app/#/setup?focus=domain -const loginClient = new LoginClient({ authressLoginHostUrl: 'https://login.application.com', applicationId: 'YOUR_APPLICATION_ID' }); +// What is my authressApiUrl? => https://authress.io/app/#/setup?focus=domain +const loginClient = new LoginClient({ authressApiUrl: 'https://login.application.com', applicationId: 'YOUR_APPLICATION_ID' }); const isUserLoggedIn = await loginClient.userSessionExists(); if (!isUserLoggedIn) { window.location.assign('/login'); diff --git a/index.d.ts b/index.d.ts index fb18e40..9ab8b94 100644 --- a/index.d.ts +++ b/index.d.ts @@ -1,6 +1,12 @@ export interface Settings { + /** + * @deprecated Use the @see authressApiUrl property instead. + */ + authressLoginHostUrl?: string; + /** Your Authress custom domain - see https://authress.io/app/#/setup?focus=domain */ - authressLoginHostUrl: string; + authressApiUrl?: string; + /** The Authress applicationId for this app - see https://authress.io/app/#/manage?focus=applications */ applicationId: string; } diff --git a/src/index.js b/src/index.js index d2ca5d8..313505c 100644 --- a/src/index.js +++ b/src/index.js @@ -17,17 +17,17 @@ class LoginClient { /** * @constructor constructs the LoginClient with a given configuration * @param {Object} settings - * @param {String} settings.authressLoginHostUrl Your Authress custom domain - see https://authress.io/app/#/manage?focus=applications + * @param {String} settings.authressApiUrl Your Authress custom domain - see https://authress.io/app/#/manage?focus=applications * @param {String} settings.applicationId the Authress applicationId for this app - see https://authress.io/app/#/manage?focus=applications * @param {Object} [logger] a configured logger object, optionally `console`, which can used to display debug and warning messages. */ constructor(settings, logger) { this.settings = Object.assign({ applicationId: 'app_default' }, settings); this.logger = logger || console; - const hostUrl = this.settings.authressLoginHostUrl || this.settings.authenticationServiceUrl || ''; + const hostUrl = this.settings.authressApiUrl || this.settings.authressLoginHostUrl || this.settings.authenticationServiceUrl || ''; if (!hostUrl) { - throw Error('Missing required property "authressLoginHostUrl" in LoginClient constructor. Custom Authress Domain Host is required.'); + throw Error('Missing required property "authressApiUrl" in LoginClient constructor. Custom Authress Domain Host is required.'); } this.hostUrl = sanitizeUrl(hostUrl); diff --git a/tests/index.test.js b/tests/index.test.js index da4105b..5d13f56 100644 --- a/tests/index.test.js +++ b/tests/index.test.js @@ -47,13 +47,13 @@ describe('index.js', () => { name: 'loginHost not set', url: null, expectedBaseUrl: 'https://login.test.com/api', - expectedError: 'Missing required property "authressLoginHostUrl" in LoginClient constructor. Custom Authress Domain Host is required.' + expectedError: 'Missing required property "authressApiUrl" in LoginClient constructor. Custom Authress Domain Host is required.' }; }; for (let test of tests) { it(test.name, () => { try { - const loginClient = new LoginClient({ authressLoginHostUrl: test.url, skipBackgroundCredentialsCheck: true }); + const loginClient = new LoginClient({ authressApiUrl: test.url, skipBackgroundCredentialsCheck: true }); expect(loginClient.httpClient.loginUrl).to.eql(test.expectedBaseUrl); expect(test.expectedError).to.eql(undefined); } catch (error) { @@ -66,41 +66,41 @@ describe('index.js', () => { describe('getMatchingDomainInfo()', () => { it('Adjacent domain returns true', () => { - const authressLoginHostUrl = 'https://security.application.com'; - const loginClient = new LoginClient({ authressLoginHostUrl, skipBackgroundCredentialsCheck: true }); + const authressApiUrl = 'https://security.application.com'; + const loginClient = new LoginClient({ authressApiUrl, skipBackgroundCredentialsCheck: true }); const window = { location: { protocol: 'https:', host: 'app.application.com' } }; - const result = loginClient.getMatchingDomainInfo(authressLoginHostUrl, window); + const result = loginClient.getMatchingDomainInfo(authressApiUrl, window); expect(result).to.eql(true); }); it('Top level domain returns true', () => { - const authressLoginHostUrl = 'https://security.application.com'; - const loginClient = new LoginClient({ authressLoginHostUrl, skipBackgroundCredentialsCheck: true }); + const authressApiUrl = 'https://security.application.com'; + const loginClient = new LoginClient({ authressApiUrl, skipBackgroundCredentialsCheck: true }); const window = { location: { protocol: 'https:', host: 'application.com' } }; - const result = loginClient.getMatchingDomainInfo(authressLoginHostUrl, window); + const result = loginClient.getMatchingDomainInfo(authressApiUrl, window); expect(result).to.eql(true); }); it('Cross domain returns false', () => { - const authressLoginHostUrl = 'https://security.application.com'; - const loginClient = new LoginClient({ authressLoginHostUrl, skipBackgroundCredentialsCheck: true }); + const authressApiUrl = 'https://security.application.com'; + const loginClient = new LoginClient({ authressApiUrl, skipBackgroundCredentialsCheck: true }); const window = { location: { protocol: 'https:', host: 'app.cross-domain.com' } }; - const result = loginClient.getMatchingDomainInfo(authressLoginHostUrl, window); + const result = loginClient.getMatchingDomainInfo(authressApiUrl, window); expect(result).to.eql(false); }); });