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

Add support for custom login URL #38

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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
10 changes: 10 additions & 0 deletions src/aad.url.builder.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(<AadUrlConfig>options).build();

expect(_.startsWith(actualUrl, expectedLocation)).toBe(true, 'incorrect location');
});

function createConfig(): AadUrlConfig {
return {
nonce: new GuidGenerator().generate(),
Expand Down
6 changes: 4 additions & 2 deletions src/aad.url.builder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
}

Expand All @@ -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;
Expand Down
1 change: 1 addition & 0 deletions src/aad.url.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,5 @@ export interface AadUrlConfig {
clientRequestId?: string;
libVersion?: string;
extraQueryParameter?: string;
loginUrl?: string;
}
3 changes: 2 additions & 1 deletion src/adal.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
};
}