Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
ba49410
Initial Commit
tnorling May 1, 2020
e5764bc
Merge branch 'dev' into cloud-discovery
tnorling May 13, 2020
d2bf765
Merge branch 'dev' into cloud-discovery
tnorling May 19, 2020
968c1b3
Merge branch 'authority-metadata-openid-perf' of https://github.com/A…
tnorling May 19, 2020
a9b9853
Move setup functions to Factory
tnorling May 19, 2020
e90cd4e
Update unit tests
tnorling May 20, 2020
c75b961
Merge branch 'authority-metadata-openid-perf' of https://github.com/A…
tnorling May 20, 2020
453bad8
Resolve lint errors
tnorling May 20, 2020
85d1736
Move validation of Authority to Factory
tnorling May 21, 2020
e0fc794
Add TrustedHostList getter
tnorling May 21, 2020
a190f8a
Update Error message
tnorling May 21, 2020
72e213b
Separate async network call
tnorling May 21, 2020
acebe0f
Fix Trusted Check
tnorling May 21, 2020
19ab0dd
Unit Tests
tnorling May 21, 2020
dc93c20
Merge branch 'dev' of https://github.com/AzureAD/microsoft-authentica…
tnorling May 21, 2020
b179c4d
Move TrustedAuthority to its own class
tnorling May 22, 2020
4d11b85
Clean up test
tnorling May 22, 2020
ff06f8b
Fix context
tnorling May 22, 2020
79e8fce
Merge branch 'dev' into cloud-discovery
tnorling May 26, 2020
80c4b6d
Add tests
tnorling May 26, 2020
22b125e
Merge branch 'dev' into cloud-discovery
tnorling Jun 1, 2020
acb0a51
Initiate cloud discovery in Constructor
tnorling Jun 2, 2020
69c53db
Fix lint errors
tnorling Jun 2, 2020
bc50c5a
Fix tests
tnorling Jun 2, 2020
01212c6
Revert "Fix tests"
tnorling Jun 3, 2020
ea9fab0
Revert "Fix lint errors"
tnorling Jun 3, 2020
e645c9e
Revert "Initiate cloud discovery in Constructor"
tnorling Jun 3, 2020
6e098e3
Merge branch 'dev' into cloud-discovery
tnorling Jun 3, 2020
c0fa200
Merge branch 'dev' of https://github.com/AzureAD/microsoft-authentica…
tnorling Jun 15, 2020
2e16854
Addressing feedback
tnorling Jun 15, 2020
84dd6a2
Merge branch 'dev' into cloud-discovery
tnorling Jun 15, 2020
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
Prev Previous commit
Next Next commit
Move validation of Authority to Factory
  • Loading branch information
tnorling committed May 21, 2020
commit 85d1736df18d0369a1933229a65d8544b85113ce
23 changes: 3 additions & 20 deletions lib/msal-core/src/authority/Authority.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

import { IUri } from "../IUri";
import { ITenantDiscoveryResponse } from "./ITenantDiscoveryResponse";
import { ClientConfigurationErrorMessage, ClientConfigurationError } from "../error/ClientConfigurationError";
import { ClientConfigurationErrorMessage } from "../error/ClientConfigurationError";
import { XhrClient, XhrResponse } from "../XHRClient";
import { UrlUtils } from "../utils/UrlUtils";
import TelemetryManager from "../telemetry/TelemetryManager";
Expand All @@ -25,18 +25,13 @@ export enum AuthorityType {
* @hidden
*/
export class Authority {
constructor(authority: string, validateAuthority: boolean, authorityMetadata?: ITenantDiscoveryResponse) {
this.IsValidationEnabled = validateAuthority;
constructor(authority: string, authorityMetadata?: ITenantDiscoveryResponse) {
this.CanonicalAuthority = authority;

this.validateAsUri();
this.tenantDiscoveryResponse = authorityMetadata;
}

public IsValidationEnabled: boolean;

public static TrustedHostList: Array<string> = [];

public get Tenant(): string {
return this.CanonicalAuthorityUrlComponents.PathSegments[0];
}
Expand Down Expand Up @@ -170,18 +165,6 @@ export class Authority {
* Only responds with the endpoint
*/
public GetOpenIdConfigurationEndpoint(): string {
if (!this.IsValidationEnabled || this.IsInTrustedHostList(this.CanonicalAuthorityUrlComponents.HostNameAndPort)) {
return this.DefaultOpenIdConfigurationEndpoint;
}

throw ClientConfigurationError.createUntrustedAuthorityError();
}

/**
* Checks to see if the host is in a list of trusted hosts
* @param {string} The host to look up
*/
private IsInTrustedHostList(host: string): boolean {
return Authority.TrustedHostList.indexOf(host.toLowerCase()) > -1;
return this.DefaultOpenIdConfigurationEndpoint;
}
}
25 changes: 20 additions & 5 deletions lib/msal-core/src/authority/AuthorityFactory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,11 @@ import { ITenantDiscoveryResponse, OpenIdConfiguration } from "./ITenantDiscover
import TelemetryManager from "../telemetry/TelemetryManager";
import { XhrClient, XhrResponse } from "../XHRClient";
import HttpEvent from "../telemetry/HttpEvent";
import { UrlUtils } from '../utils/UrlUtils';

export class AuthorityFactory {
private static metadataMap = new Map<string, ITenantDiscoveryResponse>();
private static TrustedHostList: Array<string> = [];

public static async saveMetadataFromNetwork(authorityInstance: Authority, telemetryManager: TelemetryManager, correlationId: string): Promise<ITenantDiscoveryResponse> {
const metadata = await authorityInstance.resolveEndpointsAsync(telemetryManager, correlationId);
Expand Down Expand Up @@ -51,12 +53,12 @@ export class AuthorityFactory {
* Use when validateAuthority is set to True to provide list of allowed domains.
*/
public static async setKnownAuthorities(validateAuthority: boolean, knownAuthorities: Array<string>, telemetryManager: TelemetryManager, correlationId?: string): Promise<void> {
if (validateAuthority && !Authority.TrustedHostList.length){
if (validateAuthority && !this.TrustedHostList.length){
knownAuthorities.forEach(function(authority){
Authority.TrustedHostList.push(authority);
this.TrustedHostList.push(authority.toLowerCase());
});

if (!Authority.TrustedHostList.length){
if (!this.TrustedHostList.length){
await this.setTrustedAuthoritiesFromNetwork(telemetryManager, correlationId);
}
}
Expand Down Expand Up @@ -85,11 +87,19 @@ export class AuthorityFactory {
metadata.forEach(function(entry: any){
const authorities: Array<string> = entry.aliases;
authorities.forEach(function(authority: string) {
Authority.TrustedHostList.push(authority);
this.TrustedHostList.push(authority.toLowerCase());
});
});
}

/**
* Checks to see if the host is in a list of trusted hosts
* @param {string} The host to look up
*/
public static IsInTrustedHostList(host: string): boolean {
return this.TrustedHostList.indexOf(host.toLowerCase()) > -1;
}

/**
* Create an authority object of the correct type based on the url
* Performs basic authority validation - checks to see if the authority is of a valid type (eg aad, b2c)
Expand All @@ -104,6 +114,11 @@ export class AuthorityFactory {
this.saveMetadataFromConfig(authorityUrl, authorityMetadata);
}

return new Authority(authorityUrl, validateAuthority, this.metadataMap.get(authorityUrl));
const host = UrlUtils.GetUrlComponents(authorityUrl).HostNameAndPort;
if (validateAuthority && !this.IsInTrustedHostList(host)) {
throw ClientConfigurationError.createUntrustedAuthorityError();
}

return new Authority(authorityUrl, this.metadataMap.get(authorityUrl));
}
}
4 changes: 2 additions & 2 deletions lib/msal-core/src/telemetry/TelemetryUtils.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import { Authority } from "../authority/Authority";
import { TENANT_PLACEHOLDER, EVENT_NAME_PREFIX } from "./TelemetryConstants";
import { CryptoUtils } from "../utils/CryptoUtils";
import { UrlUtils } from "../utils/UrlUtils";
import { AuthorityFactory } from '../authority/AuthorityFactory';

export const scrubTenantFromUri = (uri: string): String => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we create a utility class with static functions instead of exporting function constants?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that's reasonable but since this PR isn't really changing any telemetry files other than to fix compilation, I think that can be taken separately.


const url = UrlUtils.GetUrlComponents(uri);

// validate trusted host
if (Authority.TrustedHostList.indexOf(url.HostNameAndPort.toLocaleLowerCase()) === -1) {
if (AuthorityFactory.IsInTrustedHostList(url.HostNameAndPort.toLocaleLowerCase())) {
/**
* returning what was passed because the library needs to work with uris that are non
* AAD trusted but passed by users such as B2C or others.
Expand Down