From 48c934061a161f5899fdd3c93a99f56d649a963d Mon Sep 17 00:00:00 2001 From: Carl Vuorinen Date: Tue, 19 Dec 2017 20:05:50 +0200 Subject: [PATCH 1/2] Add support for custom login URL --- src/aad.url.builder.spec.ts | 10 ++++++++++ src/aad.url.builder.ts | 6 ++++-- src/aad.url.config.ts | 1 + src/adal.config.ts | 3 ++- 4 files changed, 17 insertions(+), 3 deletions(-) diff --git a/src/aad.url.builder.spec.ts b/src/aad.url.builder.spec.ts index 7c07ecb..31e5409 100644 --- a/src/aad.url.builder.spec.ts +++ b/src/aad.url.builder.spec.ts @@ -52,6 +52,16 @@ describe('AadUrlBuilder', () => { actualUrl = actualUrl.replace(expectedNonce, ''); }); + it('should allow using custom login url', () => { + let options = createConfig(); + options.loginUrl = 'https://my.custom.ad/' + let expectedLocation = options.loginUrl + options.tenant + '/oauth2/authorize'; + + let actualUrl = new AadUrlBuilder(new GuidGenerator()).with(options).build(); + + expect(_.startsWith(actualUrl, expectedLocation)).toBe(true, 'incorrect location'); + }); + function createConfig(): AadUrlConfig { return { nonce: new GuidGenerator().generate(), diff --git a/src/aad.url.builder.ts b/src/aad.url.builder.ts index 3281485..97184f4 100644 --- a/src/aad.url.builder.ts +++ b/src/aad.url.builder.ts @@ -13,8 +13,8 @@ export class AadUrlBuilder { private clientRequestId: string; private libVersion: string; private extraQueryParameter: string; + private loginUrl: string; private guidGenerator: GuidGenerator; - public static MicrosoftLoginUrl: string = 'https://login.microsoftonline.com/'; constructor(guidGenerator: GuidGenerator) { this.guidGenerator = guidGenerator; @@ -23,6 +23,7 @@ export class AadUrlBuilder { this.clientRequestId = this.guidGenerator.generate(); this.responseType = 'id_token'; this.libVersion = '1.0.0'; + this.loginUrl = 'https://login.microsoftonline.com/'; this.redirectUri = window.location.href; } @@ -38,12 +39,13 @@ export class AadUrlBuilder { this.clientRequestId = options.clientRequestId || this.clientRequestId; this.libVersion = options.libVersion || this.libVersion; this.extraQueryParameter = options.extraQueryParameter || this.extraQueryParameter; + this.loginUrl = options.loginUrl || this.loginUrl; return this; } public build() { - var urlNavigate = AadUrlBuilder.MicrosoftLoginUrl + this.tenant + '/oauth2/authorize'; + var urlNavigate = this.loginUrl + this.tenant + '/oauth2/authorize'; urlNavigate = urlNavigate + this.serialize() + this.addLibMetadata(); urlNavigate = urlNavigate + '&nonce=' + encodeURIComponent(this.nonce); return urlNavigate; diff --git a/src/aad.url.config.ts b/src/aad.url.config.ts index baac3e9..9816e32 100644 --- a/src/aad.url.config.ts +++ b/src/aad.url.config.ts @@ -10,4 +10,5 @@ export interface AadUrlConfig { clientRequestId?: string; libVersion?: string; extraQueryParameter?: string; + loginUrl?: string; } \ No newline at end of file diff --git a/src/adal.config.ts b/src/adal.config.ts index b25ad19..546cedf 100644 --- a/src/adal.config.ts +++ b/src/adal.config.ts @@ -5,6 +5,7 @@ export class AdalConfig { public redirectUri: string, public postLogoutRedirectUrl?: string, public responseType?: string, - public extraQueryParameter?: string) { + public extraQueryParameter?: string, + public loginUrl?: string) { }; } \ No newline at end of file From df7b74e7ff1a6d262073478efa91385e3e8d9adc Mon Sep 17 00:00:00 2001 From: Carl Vuorinen Date: Tue, 19 Dec 2017 20:27:43 +0200 Subject: [PATCH 2/2] Add missing semicolon --- src/aad.url.builder.spec.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/aad.url.builder.spec.ts b/src/aad.url.builder.spec.ts index 31e5409..da0957e 100644 --- a/src/aad.url.builder.spec.ts +++ b/src/aad.url.builder.spec.ts @@ -54,7 +54,7 @@ describe('AadUrlBuilder', () => { it('should allow using custom login url', () => { let options = createConfig(); - options.loginUrl = 'https://my.custom.ad/' + options.loginUrl = 'https://my.custom.ad/'; let expectedLocation = options.loginUrl + options.tenant + '/oauth2/authorize'; let actualUrl = new AadUrlBuilder(new GuidGenerator()).with(options).build();