@@ -106,7 +106,7 @@ public async Task<ActionResult> OidPost(
106106 Authority = config . OidEndpoint ? . Trim ( ) ,
107107 ClientId = config . OidClientId ? . Trim ( ) ,
108108 ClientSecret = config . OidSecret ? . Trim ( ) ,
109- RedirectUri = GetRequestBase ( config . SchemeOverride ) + $ "/sso/OID/{ ( Request . Path . Value . Contains ( "/start/" , StringComparison . InvariantCultureIgnoreCase ) ? "redirect" : "r" ) } /" + provider ,
109+ RedirectUri = GetRequestBase ( config . SchemeOverride , config . PortOverride ) + $ "/sso/OID/{ ( Request . Path . Value . Contains ( "/start/" , StringComparison . InvariantCultureIgnoreCase ) ? "redirect" : "r" ) } /" + provider ,
110110 Scope = string . Join ( " " , scopes . Prepend ( "openid profile" ) ) ,
111111 DisablePushedAuthorization = config . DisablePushedAuthorization ,
112112 } ;
@@ -276,7 +276,7 @@ public async Task<ActionResult> OidPost(
276276 if ( StateManager [ state ] . Valid )
277277 {
278278 _logger . LogInformation ( $ "Is request linking: { isLinking } ") ;
279- return Content ( WebResponse . Generator ( data : state , provider : provider , baseUrl : GetRequestBase ( config . SchemeOverride ) , mode : "OID" , isLinking : isLinking ) , MediaTypeNames . Text . Html ) ;
279+ return Content ( WebResponse . Generator ( data : state , provider : provider , baseUrl : GetRequestBase ( config . SchemeOverride , config . PortOverride ) , mode : "OID" , isLinking : isLinking ) , MediaTypeNames . Text . Html ) ;
280280 }
281281 else
282282 {
@@ -324,7 +324,7 @@ public async Task<ActionResult> OidChallenge(string provider, [FromQuery] bool i
324324 config . NewPath = newPath ;
325325 }
326326
327- string redirectUri = GetRequestBase ( config . SchemeOverride ) + $ "/sso/OID/{ ( newPath ? "redirect" : "r" ) } /" + provider ;
327+ string redirectUri = GetRequestBase ( config . SchemeOverride , config . PortOverride ) + $ "/sso/OID/{ ( newPath ? "redirect" : "r" ) } /" + provider ;
328328
329329 var options = new OidcClientOptions
330330 {
@@ -524,7 +524,7 @@ public ActionResult SamlPost(string provider, [FromQuery] string relayState = nu
524524 WebResponse . Generator (
525525 data : Convert . ToBase64String ( System . Text . Encoding . UTF8 . GetBytes ( samlResponse . Xml ) ) ,
526526 provider : provider ,
527- baseUrl : GetRequestBase ( config . SchemeOverride ) ,
527+ baseUrl : GetRequestBase ( config . SchemeOverride , config . PortOverride ) ,
528528 mode : "SAML" ,
529529 isLinking : isLinking ) ,
530530 MediaTypeNames . Text . Html ) ;
@@ -570,7 +570,7 @@ public RedirectResult SamlChallenge(string provider, [FromQuery] bool isLinking
570570 config . NewPath = newPath ;
571571 }
572572
573- string redirectUri = GetRequestBase ( config . SchemeOverride ) + $ "/sso/SAML/{ ( newPath ? "post" : "p" ) } /" + provider ;
573+ string redirectUri = GetRequestBase ( config . SchemeOverride , config . PortOverride ) + $ "/sso/SAML/{ ( newPath ? "post" : "p" ) } /" + provider ;
574574 string relayState = null ;
575575 if ( isLinking )
576576 {
@@ -1148,9 +1148,19 @@ private void Invalidate()
11481148 }
11491149 }
11501150
1151- private string GetRequestBase ( string schemeOverride = null )
1151+ private string GetRequestBase ( string schemeOverride = null , int ? portOverride = null )
1152+ {
1153+ int requestPort ;
1154+
1155+ if ( portOverride != null )
1156+ {
1157+ requestPort = portOverride . Value ;
1158+ }
1159+ else
11521160 {
1153- int requestPort = Request . Host . Port ?? - 1 ;
1161+ requestPort = Request . Host . Port ?? - 1 ;
1162+ }
1163+
11541164 if ( ( requestPort == 80 && string . Equals ( Request . Scheme , "http" , StringComparison . OrdinalIgnoreCase ) ) || ( requestPort == 443 && string . Equals ( Request . Scheme , "https" , StringComparison . OrdinalIgnoreCase ) ) )
11551165 {
11561166 requestPort = - 1 ;
0 commit comments