Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Don't coerce http to https if requested. #31

Merged
merged 1 commit into from
Dec 24, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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