Skip to content

Commit

Permalink
Don't coerce http to https if requested.
Browse files Browse the repository at this point in the history
  • Loading branch information
wparad committed Dec 24, 2023
1 parent 2ae36c5 commit d086b2d
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 4 deletions.
3 changes: 2 additions & 1 deletion src/extensionClient.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
const base64url = require('./base64url');

const jwtManager = require('./jwtManager');
const { sanitizeUrl } = require('./util');

const AuthenticationRequestNonceKey = 'ExtensionRequestNonce';

Expand All @@ -23,7 +24,7 @@ class ExtensionClient {
throw Error('Missing required property "extensionId" in ExtensionClient constructor. The extension is required for selecting the correct login method.');
}

this.authressCustomDomain = `https://${authressCustomDomain.replace(/^(https?:\/+)/, '')}`;
this.authressCustomDomain = sanitizeUrl(authressCustomDomain);
this.accessToken = null;

window.onload = async () => {
Expand Down
4 changes: 3 additions & 1 deletion src/httpClient.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
const { sanitizeUrl } = require('./util');

const defaultHeaders = {
'Content-Type': 'application/json'
};
Expand Down Expand Up @@ -43,7 +45,7 @@ class HttpClient {
const logger = overrideLogger || { debug() {}, warn() {}, critical() {} };
this.logger = logger;

const loginHostFullUrl = new URL(`https://${authressLoginCustomDomain.replace(/^(https?:\/+)/, '')}`);
const loginHostFullUrl = new URL(sanitizeUrl(authressLoginCustomDomain));
this.loginUrl = `${loginHostFullUrl.origin}/api`;
}

Expand Down
3 changes: 2 additions & 1 deletion src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ const take = require('lodash.take');

const HttpClient = require('./httpClient');
const jwtManager = require('./jwtManager');
const { sanitizeUrl } = require('./util');
const userIdentityTokenStorageManager = require('./userIdentityTokenStorageManager');

let userSessionResolver;
Expand All @@ -29,7 +30,7 @@ class LoginClient {
throw Error('Missing required property "authressLoginHostUrl" in LoginClient constructor. Custom Authress Domain Host is required.');
}

this.hostUrl = `https://${hostUrl.replace(/^(https?:\/+)/, '')}`;
this.hostUrl = sanitizeUrl(hostUrl);
this.httpClient = new HttpClient(this.hostUrl, this.logger);
this.lastSessionCheck = 0;

Expand Down
7 changes: 7 additions & 0 deletions src/util.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
module.exports.sanitizeUrl = function sanitizeUrl(url) {
if (url.startsWith('http')) {
return url;
}

return `https://${url}`;
};
2 changes: 1 addition & 1 deletion tests/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ describe('index.js', () => {
yield {
name: 'loginHost set correctly from http',
url: 'http://login.test.com',
expectedBaseUrl: 'https://login.test.com/api'
expectedBaseUrl: 'http://login.test.com/api'
};

yield {
Expand Down

0 comments on commit d086b2d

Please sign in to comment.