@@ -690,11 +690,14 @@ func TestBuildAuthServerRunConfig(t *testing.T) {
690690 defaultAudiences := []string {"http://test-server.default.svc.cluster.local:8080" }
691691 defaultScopes := []string {"openid" , "offline_access" }
692692
693+ defaultResourceURL := "http://test-server.default.svc.cluster.local:8080"
694+
693695 tests := []struct {
694696 name string
695697 authConfig * mcpv1alpha1.EmbeddedAuthServerConfig
696698 allowedAudiences []string
697699 scopesSupported []string
700+ resourceURL string
698701 checkFunc func (t * testing.T , config * authserver.RunConfig )
699702 }{
700703 {
@@ -774,7 +777,8 @@ func TestBuildAuthServerRunConfig(t *testing.T) {
774777 },
775778 },
776779 {
777- name : "with OIDC upstream provider" ,
780+ name : "with OIDC upstream provider" ,
781+ resourceURL : defaultResourceURL ,
778782 authConfig : & mcpv1alpha1.EmbeddedAuthServerConfig {
779783 Issuer : "https://auth.example.com" ,
780784 SigningKeySecretRefs : []mcpv1alpha1.SecretKeyRef {
@@ -811,7 +815,8 @@ func TestBuildAuthServerRunConfig(t *testing.T) {
811815 },
812816 },
813817 {
814- name : "with OAuth2 upstream provider with userinfo config" ,
818+ name : "with OAuth2 upstream provider with userinfo config" ,
819+ resourceURL : defaultResourceURL ,
815820 authConfig : & mcpv1alpha1.EmbeddedAuthServerConfig {
816821 Issuer : "https://auth.example.com" ,
817822 SigningKeySecretRefs : []mcpv1alpha1.SecretKeyRef {
@@ -904,7 +909,8 @@ func TestBuildAuthServerRunConfig(t *testing.T) {
904909 },
905910 },
906911 {
907- name : "with multiple upstream providers all are included" ,
912+ name : "with multiple upstream providers all are included" ,
913+ resourceURL : defaultResourceURL ,
908914 authConfig : & mcpv1alpha1.EmbeddedAuthServerConfig {
909915 Issuer : "https://auth.example.com" ,
910916 SigningKeySecretRefs : []mcpv1alpha1.SecretKeyRef {
@@ -1041,13 +1047,141 @@ func TestBuildAuthServerRunConfig(t *testing.T) {
10411047 upstream .OAuth2Config .AdditionalAuthorizationParams )
10421048 },
10431049 },
1050+ {
1051+ name : "OIDC upstream with empty redirectUri defaults to resourceURL/oauth/callback" ,
1052+ resourceURL : "https://mcp.example.com" ,
1053+ authConfig : & mcpv1alpha1.EmbeddedAuthServerConfig {
1054+ Issuer : "https://auth.example.com" ,
1055+ SigningKeySecretRefs : []mcpv1alpha1.SecretKeyRef {
1056+ {Name : "signing-key" , Key : "private.pem" },
1057+ },
1058+ HMACSecretRefs : []mcpv1alpha1.SecretKeyRef {
1059+ {Name : "hmac-secret" , Key : "hmac" },
1060+ },
1061+ UpstreamProviders : []mcpv1alpha1.UpstreamProviderConfig {
1062+ {
1063+ Name : "okta" ,
1064+ Type : mcpv1alpha1 .UpstreamProviderTypeOIDC ,
1065+ OIDCConfig : & mcpv1alpha1.OIDCUpstreamConfig {
1066+ IssuerURL : "https://okta.example.com" ,
1067+ ClientID : "client-id" ,
1068+ // RedirectURI intentionally omitted
1069+ },
1070+ },
1071+ },
1072+ },
1073+ allowedAudiences : defaultAudiences ,
1074+ scopesSupported : defaultScopes ,
1075+ checkFunc : func (t * testing.T , config * authserver.RunConfig ) {
1076+ t .Helper ()
1077+ require .Len (t , config .Upstreams , 1 )
1078+ require .NotNil (t , config .Upstreams [0 ].OIDCConfig )
1079+ assert .Equal (t , "https://mcp.example.com/oauth/callback" , config .Upstreams [0 ].OIDCConfig .RedirectURI )
1080+ },
1081+ },
1082+ {
1083+ name : "OAuth2 upstream with empty redirectUri defaults to resourceURL/oauth/callback" ,
1084+ resourceURL : "https://mcp.example.com" ,
1085+ authConfig : & mcpv1alpha1.EmbeddedAuthServerConfig {
1086+ Issuer : "https://auth.example.com" ,
1087+ SigningKeySecretRefs : []mcpv1alpha1.SecretKeyRef {
1088+ {Name : "signing-key" , Key : "private.pem" },
1089+ },
1090+ HMACSecretRefs : []mcpv1alpha1.SecretKeyRef {
1091+ {Name : "hmac-secret" , Key : "hmac" },
1092+ },
1093+ UpstreamProviders : []mcpv1alpha1.UpstreamProviderConfig {
1094+ {
1095+ Name : "github" ,
1096+ Type : mcpv1alpha1 .UpstreamProviderTypeOAuth2 ,
1097+ OAuth2Config : & mcpv1alpha1.OAuth2UpstreamConfig {
1098+ AuthorizationEndpoint : "https://github.com/login/oauth/authorize" ,
1099+ TokenEndpoint : "https://github.com/login/oauth/access_token" ,
1100+ ClientID : "client-id" ,
1101+ // RedirectURI intentionally omitted
1102+ },
1103+ },
1104+ },
1105+ },
1106+ allowedAudiences : defaultAudiences ,
1107+ scopesSupported : defaultScopes ,
1108+ checkFunc : func (t * testing.T , config * authserver.RunConfig ) {
1109+ t .Helper ()
1110+ require .Len (t , config .Upstreams , 1 )
1111+ require .NotNil (t , config .Upstreams [0 ].OAuth2Config )
1112+ assert .Equal (t , "https://mcp.example.com/oauth/callback" , config .Upstreams [0 ].OAuth2Config .RedirectURI )
1113+ },
1114+ },
1115+ {
1116+ name : "explicit redirectUri is preserved when resourceURL is also set" ,
1117+ resourceURL : "https://mcp.example.com" ,
1118+ authConfig : & mcpv1alpha1.EmbeddedAuthServerConfig {
1119+ Issuer : "https://auth.example.com" ,
1120+ SigningKeySecretRefs : []mcpv1alpha1.SecretKeyRef {
1121+ {Name : "signing-key" , Key : "private.pem" },
1122+ },
1123+ HMACSecretRefs : []mcpv1alpha1.SecretKeyRef {
1124+ {Name : "hmac-secret" , Key : "hmac" },
1125+ },
1126+ UpstreamProviders : []mcpv1alpha1.UpstreamProviderConfig {
1127+ {
1128+ Name : "okta" ,
1129+ Type : mcpv1alpha1 .UpstreamProviderTypeOIDC ,
1130+ OIDCConfig : & mcpv1alpha1.OIDCUpstreamConfig {
1131+ IssuerURL : "https://okta.example.com" ,
1132+ ClientID : "client-id" ,
1133+ RedirectURI : "https://custom.example.com/callback" ,
1134+ },
1135+ },
1136+ },
1137+ },
1138+ allowedAudiences : defaultAudiences ,
1139+ scopesSupported : defaultScopes ,
1140+ checkFunc : func (t * testing.T , config * authserver.RunConfig ) {
1141+ t .Helper ()
1142+ require .Len (t , config .Upstreams , 1 )
1143+ require .NotNil (t , config .Upstreams [0 ].OIDCConfig )
1144+ assert .Equal (t , "https://custom.example.com/callback" , config .Upstreams [0 ].OIDCConfig .RedirectURI )
1145+ },
1146+ },
1147+ {
1148+ name : "resourceURL with trailing slash produces correct default redirectUri" ,
1149+ resourceURL : "https://mcp.example.com/" ,
1150+ authConfig : & mcpv1alpha1.EmbeddedAuthServerConfig {
1151+ Issuer : "https://auth.example.com" ,
1152+ SigningKeySecretRefs : []mcpv1alpha1.SecretKeyRef {
1153+ {Name : "signing-key" , Key : "private.pem" },
1154+ },
1155+ HMACSecretRefs : []mcpv1alpha1.SecretKeyRef {
1156+ {Name : "hmac-secret" , Key : "hmac" },
1157+ },
1158+ UpstreamProviders : []mcpv1alpha1.UpstreamProviderConfig {
1159+ {
1160+ Name : "okta" ,
1161+ Type : mcpv1alpha1 .UpstreamProviderTypeOIDC ,
1162+ OIDCConfig : & mcpv1alpha1.OIDCUpstreamConfig {
1163+ IssuerURL : "https://okta.example.com" ,
1164+ ClientID : "client-id" ,
1165+ },
1166+ },
1167+ },
1168+ },
1169+ allowedAudiences : defaultAudiences ,
1170+ scopesSupported : defaultScopes ,
1171+ checkFunc : func (t * testing.T , config * authserver.RunConfig ) {
1172+ t .Helper ()
1173+ require .Len (t , config .Upstreams , 1 )
1174+ require .NotNil (t , config .Upstreams [0 ].OIDCConfig )
1175+ assert .Equal (t , "https://mcp.example.com/oauth/callback" , config .Upstreams [0 ].OIDCConfig .RedirectURI )
1176+ },
1177+ },
10441178 }
10451179
10461180 for _ , tt := range tests {
10471181 t .Run (tt .name , func (t * testing.T ) {
10481182 t .Parallel ()
10491183
1050- config , err := BuildAuthServerRunConfig ("default" , "test-server" , tt .authConfig , tt .allowedAudiences , tt .scopesSupported )
1184+ config , err := BuildAuthServerRunConfig ("default" , "test-server" , tt .authConfig , tt .allowedAudiences , tt .scopesSupported , tt . resourceURL )
10511185
10521186 require .NoError (t , err )
10531187 require .NotNil (t , config )
@@ -1634,6 +1768,7 @@ func TestBuildAuthServerRunConfig_WithRedisStorage(t *testing.T) {
16341768 "default" , "my-mcp-server" , authConfig ,
16351769 []string {"http://test-server.default.svc.cluster.local:8080" },
16361770 []string {"openid" },
1771+ "http://test-server.default.svc.cluster.local:8080" ,
16371772 )
16381773
16391774 require .NoError (t , err )
0 commit comments