@@ -64,7 +64,8 @@ struct GroupMembership {
6464}
6565
6666struct EntraEndpoint {
67- hostname : HostName ,
67+ hostname_token : HostName ,
68+ hostname_graph : HostName ,
6869 port : u16 ,
6970 tenant_id : String ,
7071 protocol : String ,
@@ -78,16 +79,18 @@ pub(crate) async fn get_user_info(
7879) -> Result < UserInfo , Error > {
7980 let v1alpha1:: EntraBackend {
8081 client_credentials_secret : _,
81- hostname,
82+ hostname_token,
83+ hostname_graph,
8284 port,
8385 tenant_id,
8486 tls,
8587 } = config;
8688
8789 let entra_endpoint = EntraEndpoint :: new (
88- hostname. clone ( ) ,
90+ hostname_token. clone ( ) ,
91+ hostname_graph. clone ( ) ,
8992 * port,
90- tenant_id. clone ( ) ,
93+ tenant_id. to_string ( ) ,
9194 & TlsClientDetails { tls : tls. clone ( ) } ,
9295 ) ;
9396 let token_url = entra_endpoint. oauth2_token ( ) ;
@@ -141,9 +144,16 @@ pub(crate) async fn get_user_info(
141144}
142145
143146impl EntraEndpoint {
144- pub fn new ( hostname : HostName , port : u16 , tenant_id : String , tls : & TlsClientDetails ) -> Self {
147+ pub fn new (
148+ hostname_token : HostName ,
149+ hostname_graph : HostName ,
150+ port : u16 ,
151+ tenant_id : String ,
152+ tls : & TlsClientDetails ,
153+ ) -> Self {
145154 Self {
146- hostname,
155+ hostname_token,
156+ hostname_graph,
147157 port,
148158 tenant_id,
149159 protocol : if tls. uses_tls ( ) {
@@ -157,7 +167,7 @@ impl EntraEndpoint {
157167 pub fn oauth2_token ( & self ) -> String {
158168 format ! (
159169 "{base_url}/{tenant_id}/oauth2/v2.0/token" ,
160- base_url = self . base_url( "login" ) ,
170+ base_url = self . base_url( & self . hostname_token ) ,
161171 tenant_id = self . tenant_id
162172 )
163173 }
@@ -166,26 +176,25 @@ impl EntraEndpoint {
166176 pub fn user_info ( & self , user : & str ) -> String {
167177 format ! (
168178 "{base_url}/v1.0/users/{user}" ,
169- base_url = self . base_url( "graph" ) ,
179+ base_url = self . base_url( & self . hostname_graph ) ,
170180 )
171181 }
172182
173183 pub fn group_info ( & self , user : & str ) -> String {
174184 format ! (
175185 "{base_url}/v1.0/users/{user}/memberOf" ,
176- base_url = self . base_url( "graph" ) ,
186+ base_url = self . base_url( & self . hostname_graph ) ,
177187 )
178188 }
179189
180- fn base_url ( & self , prefix : & str ) -> String {
190+ fn base_url ( & self , hostname : & HostName ) -> String {
181191 format ! (
182- "{protocol}://{prefix}.{ hostname}{opt_port}" ,
192+ "{protocol}://{hostname}{opt_port}" ,
183193 opt_port = if self . port == 443 || self . port == 80 {
184194 "" . to_string( )
185195 } else {
186196 format!( ":{port}" , port = self . port)
187197 } ,
188- hostname = self . hostname,
189198 protocol = self . protocol
190199 )
191200 }
@@ -204,7 +213,8 @@ mod tests {
204213 #[ test]
205214 fn test_defaults ( ) {
206215 let entra_endpoint = EntraEndpoint :: new (
207- HostName :: from_str ( "microsoft.com" ) . expect ( "Could not parse hostname" ) ,
216+ HostName :: from_str ( "login.microsoft.com" ) . expect ( "Could not parse hostname" ) ,
217+ HostName :: from_str ( "graph.microsoft.com" ) . expect ( "Could not parse hostname" ) ,
208218 443 ,
209219 "1234-5678" . to_string ( ) ,
210220 & TlsClientDetails {
@@ -233,7 +243,8 @@ mod tests {
233243 #[ test]
234244 fn test_non_defaults_tls ( ) {
235245 let entra_endpoint = EntraEndpoint :: new (
236- HostName :: from_str ( "myentra.com" ) . expect ( "Could not parse hostname" ) ,
246+ HostName :: from_str ( "login.myentra.com" ) . expect ( "Could not parse hostname" ) ,
247+ HostName :: from_str ( "graph.myentra.com" ) . expect ( "Could not parse hostname" ) ,
237248 8443 ,
238249 "1234-5678" . to_string ( ) ,
239250 & TlsClientDetails {
@@ -258,7 +269,8 @@ mod tests {
258269 #[ test]
259270 fn test_non_defaults_non_tls ( ) {
260271 let entra_endpoint = EntraEndpoint :: new (
261- HostName :: from_str ( "myentra.com" ) . expect ( "Could not parse hostname" ) ,
272+ HostName :: from_str ( "login.myentra.com" ) . expect ( "Could not parse hostname" ) ,
273+ HostName :: from_str ( "graph.myentra.com" ) . expect ( "Could not parse hostname" ) ,
262274 8080 ,
263275 "1234-5678" . to_string ( ) ,
264276 & TlsClientDetails { tls : None } ,
0 commit comments