-
Notifications
You must be signed in to change notification settings - Fork 2.7k
B2C Authority fixes #1276
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
B2C Authority fixes #1276
Changes from 17 commits
775d59a
e6e44ca
8bef92f
4fd2c47
cf918c3
02f9528
1798a83
b9c7680
3b59547
0827b81
a78b15b
07e6dd2
92f2067
0a96df5
da3cf68
bc90b09
352e3f1
95c5fcb
f8de5a2
15d65d9
8f5d27b
ee97b68
21324e5
3c3e5c7
10779ca
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,25 +9,31 @@ | |
import { AadAuthority } from "./AadAuthority"; | ||
import { B2cAuthority } from "./B2cAuthority"; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Other end of the circle There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
import { Authority, AuthorityType } from "./Authority"; | ||
import { ClientConfigurationErrorMessage } from "../error/ClientConfigurationError"; | ||
import { UrlUtils } from "../utils/UrlUtils"; | ||
import { StringUtils } from "../utils/StringUtils"; | ||
import { UrlUtils } from "../utils/UrlUtils"; | ||
import { ClientConfigurationError } from "../error/ClientConfigurationError"; | ||
import { B2CTrustedHostList } from "../utils/Constants"; | ||
|
||
export class AuthorityFactory { | ||
|
||
/** | ||
* Parse the url and determine the type of authority | ||
*/ | ||
private static DetectAuthorityFromUrl(authorityUrl: string): AuthorityType { | ||
private static detectAuthorityFromUrl(authorityUrl: string): AuthorityType { | ||
authorityUrl = UrlUtils.CanonicalizeUri(authorityUrl); | ||
const components = UrlUtils.GetUrlComponents(authorityUrl); | ||
const pathSegments = components.PathSegments; | ||
switch (pathSegments[0]) { | ||
case "tfp": | ||
return AuthorityType.B2C; | ||
default: | ||
return AuthorityType.Aad; | ||
|
||
if (pathSegments[0] === "adfs") { | ||
return AuthorityType.Adfs; | ||
} | ||
} | ||
else if (Object.keys(B2CTrustedHostList).length) { | ||
return AuthorityType.B2C; | ||
} | ||
|
||
// Defaults to Aad | ||
return AuthorityType.Aad; | ||
} | ||
|
||
/** | ||
* Create an authority object of the correct type based on the url | ||
|
@@ -37,15 +43,15 @@ export class AuthorityFactory { | |
if (StringUtils.isEmpty(authorityUrl)) { | ||
return null; | ||
} | ||
const type = AuthorityFactory.DetectAuthorityFromUrl(authorityUrl); | ||
const type = AuthorityFactory.detectAuthorityFromUrl(authorityUrl); | ||
// Depending on above detection, create the right type. | ||
switch (type) { | ||
case AuthorityType.B2C: | ||
return new B2cAuthority(authorityUrl, validateAuthority); | ||
case AuthorityType.Aad: | ||
return new AadAuthority(authorityUrl, validateAuthority); | ||
default: | ||
throw ClientConfigurationErrorMessage.invalidAuthorityType; | ||
throw ClientConfigurationError.createInvalidAuthorityTypeError(); | ||
} | ||
} | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -107,6 +107,8 @@ export const AADTrustedHostList = { | |
"login.microsoftonline.us": "login.microsoftonline.us" | ||
}; | ||
|
||
export const B2CTrustedHostList = {}; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I would consider moving this to AuthorityFactory or B2CAuthority since it isn't actually a constant. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm also not a huge fan of having a global variable like this, I think it should be a property or field of an object or class There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Moved this to AuthorityFactory but not sure how to avoid making it global since it needs to be read from the static detectAuthorityFromUrl function. |
||
|
||
/** | ||
* @hidden | ||
* SSO Types - generated to populate hints | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
import { expect } from "chai"; | ||
import { AuthorityType } from "../../src/authority/Authority"; | ||
import { AadAuthority } from "../../src/authority/AadAuthority"; | ||
import { AADTrustedHostList } from "../../src/utils/Constants"; | ||
import { TEST_CONFIG } from "../TestConstants"; | ||
|
||
describe("AadAuthority.ts Class", function () { | ||
|
||
it("tests initialization of aad authority", function() { | ||
const authority = new AadAuthority(TEST_CONFIG.validAuthority, false); | ||
|
||
expect(authority).to.be.instanceOf(AadAuthority); | ||
expect(authority.AuthorityType).to.be.equal(AuthorityType.Aad); | ||
}); | ||
|
||
it("tests GetOpenIdConfigurationEndpointAsync with validateAuthority false", async function () { | ||
const authority = new AadAuthority(TEST_CONFIG.validAuthority, false); | ||
const endpoint = await authority.GetOpenIdConfigurationEndpointAsync(); | ||
|
||
expect(endpoint).to.include("/v2.0/.well-known/openid-configuration"); | ||
}); | ||
|
||
it("tests GetOpenIdConfigurationEndpointAsync with validateAuthority true", async function () { | ||
const authority = new AadAuthority(TEST_CONFIG.validAuthority, true); | ||
const endpoint = await authority.GetOpenIdConfigurationEndpointAsync(); | ||
|
||
expect(endpoint).to.include("/v2.0/.well-known/openid-configuration"); | ||
}); | ||
|
||
it("tests GetOpenIdConfigurationEndpointAsync with validateAuthority true and not in trusted host list", async function () { | ||
|
||
delete AADTrustedHostList["login.microsoftonline.com"]; | ||
const authority = new AadAuthority(TEST_CONFIG.validAuthority, true); | ||
const endpoint = await authority.GetOpenIdConfigurationEndpointAsync(); | ||
AADTrustedHostList["login.microsoftonline.com"] = "login.microsoftonline.com"; | ||
|
||
expect(endpoint).to.include("/v2.0/.well-known/openid-configuration"); | ||
}); | ||
|
||
}); |
Uh oh!
There was an error while loading. Please reload this page.