66import java .util .Locale ;
77
88import javax .annotation .Nonnull ;
9+ import javax .annotation .Nullable ;
910
1011/**
1112 * Provides basic common methods for all authentication providers
1213 */
1314public abstract class BaseAuthenticationProvider implements IAuthenticationProvider {
1415 private static final HashSet <String > validGraphHostNames = new HashSet <>(Arrays .asList ("graph.microsoft.com" , "graph.microsoft.us" , "dod-graph.microsoft.us" , "graph.microsoft.de" , "microsoftgraph.chinacloudapi.cn" , "canary.graph.microsoft.com" ));
16+ private HashSet <String > customHosts ;
17+
18+ /**
19+ * Allow the user to add custom hosts by passing in Array
20+ * @param customHosts custom hosts passed in by user.
21+ */
22+ public void setCustomHosts (@ Nonnull String [] customHosts ) {
23+ if (this .customHosts == null ){
24+ this .customHosts = new HashSet <String >();
25+ }
26+ for (String host : customHosts ){
27+ this .customHosts .add (host .toLowerCase (Locale .ROOT ));
28+ }
29+ }
30+ /**
31+ * Get the custom hosts set by user.
32+ * @return the custom hosts set by user.
33+ */
34+ @ Nullable
35+ public String [] getCustomHosts (){
36+ return customHosts .toArray (new String [customHosts .size ()]);
37+ }
1538 /**
1639 * Determines whether a request should be authenticated or not based on it's url.
1740 * If you're implementing a custom provider, call that method first before getting the token
@@ -22,6 +45,6 @@ protected boolean shouldAuthenticateRequestWithUrl(@Nonnull final URL requestUrl
2245 if (requestUrl == null || !requestUrl .getProtocol ().toLowerCase (Locale .ROOT ).equals ("https" ))
2346 return false ;
2447 final String hostName = requestUrl .getHost ().toLowerCase (Locale .ROOT );
25- return validGraphHostNames .contains (hostName );
48+ return customHosts == null ? ( validGraphHostNames .contains (hostName )) : ( customHosts . contains ( hostName ) );
2649 }
2750}
0 commit comments