@@ -2,6 +2,7 @@ import TelemetryManager from "../telemetry/TelemetryManager";
2
2
import { XhrClient , XhrResponse } from "../XHRClient" ;
3
3
import HttpEvent from "../telemetry/HttpEvent" ;
4
4
import { AAD_INSTANCE_DISCOVERY_ENDPOINT , NetworkRequestType } from "../utils/Constants" ;
5
+ import { UrlUtils } from '../utils/UrlUtils' ;
5
6
6
7
export class TrustedAuthority {
7
8
private static TrustedHostList : Array < string > = [ ] ;
@@ -24,12 +25,13 @@ export class TrustedAuthority {
24
25
* @param telemetryManager
25
26
* @param correlationId
26
27
*/
27
- private static async getAliases ( telemetryManager : TelemetryManager , correlationId ?: string ) : Promise < Array < any > > {
28
+ private static async getAliases ( authorityToVerify : string , telemetryManager : TelemetryManager , correlationId ?: string ) : Promise < Array < any > > {
28
29
const client : XhrClient = new XhrClient ( ) ;
29
30
30
31
const httpMethod = NetworkRequestType . GET ;
31
- const httpEvent : HttpEvent = telemetryManager . createAndStartHttpEvent ( correlationId , httpMethod , AAD_INSTANCE_DISCOVERY_ENDPOINT , "getAliases" ) ;
32
- return client . sendRequestAsync ( AAD_INSTANCE_DISCOVERY_ENDPOINT , httpMethod , true )
32
+ const instanceDiscoveryEndpoint = `${ AAD_INSTANCE_DISCOVERY_ENDPOINT } ${ authorityToVerify } oauth2/v2.0/authorize` ;
33
+ const httpEvent : HttpEvent = telemetryManager . createAndStartHttpEvent ( correlationId , httpMethod , instanceDiscoveryEndpoint , "getAliases" ) ;
34
+ return client . sendRequestAsync ( instanceDiscoveryEndpoint , httpMethod , true )
33
35
. then ( ( response : XhrResponse ) => {
34
36
httpEvent . httpResponseStatus = response . statusCode ;
35
37
telemetryManager . stopEvent ( httpEvent ) ;
@@ -47,14 +49,20 @@ export class TrustedAuthority {
47
49
* @param telemetryManager
48
50
* @param correlationId
49
51
*/
50
- public static async setTrustedAuthoritiesFromNetwork ( telemetryManager : TelemetryManager , correlationId ?: string ) : Promise < void > {
51
- const metadata = await this . getAliases ( telemetryManager , correlationId ) ;
52
+ public static async setTrustedAuthoritiesFromNetwork ( authorityToVerify : string , telemetryManager : TelemetryManager , correlationId ?: string ) : Promise < void > {
53
+ const metadata = await this . getAliases ( authorityToVerify , telemetryManager , correlationId ) ;
52
54
metadata . forEach ( function ( entry : any ) {
53
55
const authorities : Array < string > = entry . aliases ;
54
56
authorities . forEach ( function ( authority : string ) {
55
57
TrustedAuthority . TrustedHostList . push ( authority . toLowerCase ( ) ) ;
56
58
} ) ;
57
59
} ) ;
60
+
61
+ const host = UrlUtils . GetUrlComponents ( authorityToVerify ) . HostNameAndPort ;
62
+ if ( TrustedAuthority . getTrustedHostList ( ) . length && ! TrustedAuthority . IsInTrustedHostList ( host ) ) {
63
+ // Custom Domain scenario, host is trusted because Instance Discovery call succeeded
64
+ TrustedAuthority . TrustedHostList . push ( host . toLowerCase ( ) ) ;
65
+ }
58
66
}
59
67
60
68
public static getTrustedHostList ( ) : Array < string > {
0 commit comments