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
Initiate cloud discovery in Constructor
  • Loading branch information
tnorling committed Jun 2, 2020
commit acb0a514ec62dbfbdd6bc10994c872885ec47c5e
3 changes: 1 addition & 2 deletions lib/msal-core/src/UserAgentApplication.ts
Original file line number Diff line number Diff line change
Expand Up @@ -220,8 +220,7 @@ export class UserAgentApplication {

this.telemetryManager = this.getTelemetryManagerFromConfig(this.config.system.telemetry, this.clientId);

TrustedAuthority.setTrustedAuthoritiesFromConfig(this.config.auth.validateAuthority, this.config.auth.knownAuthorities);
AuthorityFactory.saveMetadataFromConfig(this.config.auth.authority, this.config.auth.authorityMetadata);
AuthorityFactory.initializeAuthorityData(this.config.auth, this.telemetryManager);

// if no authority is passed, set the default: "https://login.microsoftonline.com/common"
this.authority = this.config.auth.authority || DEFAULT_AUTHORITY;
Expand Down
3 changes: 0 additions & 3 deletions lib/msal-core/src/authority/Authority.ts
Original file line number Diff line number Diff line change
Expand Up @@ -144,9 +144,6 @@ export class Authority {
public async resolveEndpointsAsync(telemetryManager: TelemetryManager, correlationId: string): Promise<ITenantDiscoveryResponse> {
if (this.IsValidationEnabled) {
const host = this.canonicalAuthorityUrlComponents.HostNameAndPort;
if (TrustedAuthority.getTrustedHostList().length === 0) {
await TrustedAuthority.setTrustedAuthoritiesFromNetwork(telemetryManager, correlationId);
}

if (!TrustedAuthority.IsInTrustedHostList(host)) {
throw ClientConfigurationError.createUntrustedAuthorityError(host);
Expand Down
15 changes: 15 additions & 0 deletions lib/msal-core/src/authority/AuthorityFactory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,15 @@ import { StringUtils } from "../utils/StringUtils";
import { ClientConfigurationError } from "../error/ClientConfigurationError";
import { ITenantDiscoveryResponse, OpenIdConfiguration } from "./ITenantDiscoveryResponse";
import TelemetryManager from "../telemetry/TelemetryManager";
import { AuthOptions } from '../Configuration';
import { TrustedAuthority } from './TrustedAuthority';

export class AuthorityFactory {
private static metadataMap = new Map<string, ITenantDiscoveryResponse>();
private static cloudInstanceDiscoveryPromise: Promise<void>;

public static async saveMetadataFromNetwork(authorityInstance: Authority, telemetryManager: TelemetryManager, correlationId: string): Promise<ITenantDiscoveryResponse> {
await this.cloudInstanceDiscoveryPromise;
const metadata = await authorityInstance.resolveEndpointsAsync(telemetryManager, correlationId);
this.metadataMap.set(authorityInstance.CanonicalAuthority, metadata);
return metadata;
Expand Down Expand Up @@ -45,6 +49,17 @@ export class AuthorityFactory {
}
}

/**
*
* @param authConfig
* @param telemetryManager
*/
public static initializeAuthorityData(authConfig: AuthOptions, telemetryManager: TelemetryManager) {
TrustedAuthority.setTrustedAuthoritiesFromConfig(authConfig.validateAuthority, authConfig.knownAuthorities);
this.saveMetadataFromConfig(authConfig.authority, authConfig.authorityMetadata);
this.cloudInstanceDiscoveryPromise = TrustedAuthority.setTrustedAuthoritiesFromNetwork(authConfig.validateAuthority, telemetryManager);
}

/**
* 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 Down
57 changes: 28 additions & 29 deletions lib/msal-core/src/authority/TrustedAuthority.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,37 +24,36 @@ export class TrustedAuthority {
* @param telemetryManager
* @param correlationId
*/
private static async getAliases(telemetryManager: TelemetryManager, correlationId?: string): Promise<Array<any>> {
const client: XhrClient = new XhrClient();
public static setTrustedAuthoritiesFromNetwork(validateAuthority: boolean, telemetryManager: TelemetryManager, correlationId?: string): Promise<void> {
if (!validateAuthority || this.getTrustedHostList().length > 0) {
return Promise.resolve();
}

const httpMethod = "GET";
const httpEvent: HttpEvent = telemetryManager.createAndStartHttpEvent(correlationId, httpMethod, AAD_INSTANCE_DISCOVERY_ENDPOINT, "getAliases");
return client.sendRequestAsync(AAD_INSTANCE_DISCOVERY_ENDPOINT, httpMethod, true)
.then((response: XhrResponse) => {
httpEvent.httpResponseStatus = response.statusCode;
telemetryManager.stopEvent(httpEvent);
return response.body.metadata;
})
.catch(err => {
httpEvent.serverErrorCode = err;
telemetryManager.stopEvent(httpEvent);
throw err;
});
}
return new Promise<void>((resolve, reject) => {
const client: XhrClient = new XhrClient();

/**
*
* @param telemetryManager
* @param correlationId
*/
public static async setTrustedAuthoritiesFromNetwork(telemetryManager: TelemetryManager, correlationId?: string): Promise<void> {
const metadata = await this.getAliases(telemetryManager, correlationId);
metadata.forEach(function(entry: any){
const authorities: Array<string> = entry.aliases;
authorities.forEach(function(authority: string) {
TrustedAuthority.TrustedHostList.push(authority.toLowerCase());
});
});
const httpMethod = "GET";
const httpEvent: HttpEvent = telemetryManager.createAndStartHttpEvent(correlationId, httpMethod, AAD_INSTANCE_DISCOVERY_ENDPOINT, "getAliases");
client.sendRequestAsync(AAD_INSTANCE_DISCOVERY_ENDPOINT, httpMethod, true)
.then((response: XhrResponse) => {
httpEvent.httpResponseStatus = response.statusCode;
telemetryManager.stopEvent(httpEvent);

response.body.metadata.forEach(function(entry: any){
const authorities: Array<string> = entry.aliases;
authorities.forEach(function(authority: string) {
TrustedAuthority.TrustedHostList.push(authority.toLowerCase());
});
});

resolve();
})
.catch(err => {
httpEvent.serverErrorCode = err;
telemetryManager.stopEvent(httpEvent);
reject(err);
});
})
}

public static getTrustedHostList(): Array<string> {
Expand Down