Skip to content

Commit

Permalink
Add consistently named property: authressApiUrl.
Browse files Browse the repository at this point in the history
  • Loading branch information
wparad committed Jan 21, 2024
1 parent 5f94315 commit 9eb9f65
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 17 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down
8 changes: 7 additions & 1 deletion index.d.ts
Original file line number Diff line number Diff line change
@@ -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;
}
Expand Down
6 changes: 3 additions & 3 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
22 changes: 11 additions & 11 deletions tests/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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);
});
});
Expand Down

0 comments on commit 9eb9f65

Please sign in to comment.