@@ -925,18 +925,15 @@ func (api *API) userOIDC(rw http.ResponseWriter, r *http.Request) {
925
925
picture , _ = pictureRaw .(string )
926
926
}
927
927
928
- usingGroups , groups , err := api .oidcGroups (ctx , mergedClaims )
929
- if err != nil {
930
- httpapi .Write (ctx , rw , http .StatusBadRequest , codersdk.Response {
931
- Message : "Failed to sync groups from OIDC claims" ,
932
- Detail : err .Error (),
933
- })
928
+ usingGroups , groups , groupErr := api .oidcGroups (ctx , mergedClaims )
929
+ if groupErr != nil {
930
+ groupErr .Write (rw , r )
934
931
return
935
932
}
936
933
937
- roles , ok := api .oidcRoles (ctx , rw , r , mergedClaims )
938
- if ! ok {
939
- // oidcRoles writes the error to the response writer for us.
934
+ roles , roleErr := api .oidcRoles (ctx , mergedClaims )
935
+ if roleErr != nil {
936
+ roleErr . Write ( rw , r )
940
937
return
941
938
}
942
939
@@ -1009,7 +1006,7 @@ func (api *API) userOIDC(rw http.ResponseWriter, r *http.Request) {
1009
1006
}
1010
1007
1011
1008
// oidcGroups returns the groups for the user from the OIDC claims.
1012
- func (api * API ) oidcGroups (ctx context.Context , mergedClaims map [string ]interface {}) (bool , []string , error ) {
1009
+ func (api * API ) oidcGroups (ctx context.Context , mergedClaims map [string ]interface {}) (bool , []string , * httpError ) {
1013
1010
logger := api .Logger .Named (userAuthLoggerName )
1014
1011
usingGroups := false
1015
1012
var groups []string
@@ -1026,7 +1023,12 @@ func (api *API) oidcGroups(ctx context.Context, mergedClaims map[string]interfac
1026
1023
slog .F ("type" , fmt .Sprintf ("%T" , groupsRaw )),
1027
1024
slog .Error (err ),
1028
1025
)
1029
- return false , nil , err
1026
+ return false , nil , & httpError {
1027
+ code : http .StatusBadRequest ,
1028
+ msg : "Failed to sync groups from OIDC claims" ,
1029
+ detail : err .Error (),
1030
+ renderStaticPage : false ,
1031
+ }
1030
1032
}
1031
1033
1032
1034
api .Logger .Debug (ctx , "groups returned in oidc claims" ,
@@ -1058,10 +1060,10 @@ func (api *API) oidcGroups(ctx context.Context, mergedClaims map[string]interfac
1058
1060
// It would be preferred to just return an error, however this function
1059
1061
// decorates returned errors with the appropriate HTTP status codes and details
1060
1062
// that are hard to carry in a standard `error` without more work.
1061
- func (api * API ) oidcRoles (ctx context.Context , rw http. ResponseWriter , r * http. Request , mergedClaims map [string ]interface {}) ([]string , bool ) {
1063
+ func (api * API ) oidcRoles (ctx context.Context , mergedClaims map [string ]interface {}) ([]string , * httpError ) {
1062
1064
roles := api .OIDCConfig .UserRolesDefault
1063
1065
if ! api .OIDCConfig .RoleSyncEnabled () {
1064
- return roles , true
1066
+ return roles , nil
1065
1067
}
1066
1068
1067
1069
rolesRow , ok := mergedClaims [api .OIDCConfig .UserRoleField ]
@@ -1080,15 +1082,12 @@ func (api *API) oidcRoles(ctx context.Context, rw http.ResponseWriter, r *http.R
1080
1082
slog .F ("type" , fmt .Sprintf ("%T" , rolesRow )),
1081
1083
slog .Error (err ),
1082
1084
)
1083
- site .RenderStaticErrorPage (rw , r , site.ErrorPageData {
1084
- Status : http .StatusInternalServerError ,
1085
- HideStatus : true ,
1086
- Title : "Login disabled until OIDC config is fixed" ,
1087
- Description : fmt .Sprintf ("Roles claim must be an array of strings, type found: %T. Disabling role sync will allow login to proceed." , rolesRow ),
1088
- RetryEnabled : false ,
1089
- DashboardURL : "/login" ,
1090
- })
1091
- return nil , false
1085
+ return nil , & httpError {
1086
+ code : http .StatusInternalServerError ,
1087
+ msg : "Login disabled until OIDC config is fixed" ,
1088
+ detail : fmt .Sprintf ("Roles claim must be an array of strings, type found: %T. Disabling role sync will allow login to proceed." , rolesRow ),
1089
+ renderStaticPage : false ,
1090
+ }
1092
1091
}
1093
1092
1094
1093
api .Logger .Debug (ctx , "roles returned in oidc claims" ,
@@ -1107,7 +1106,7 @@ func (api *API) oidcRoles(ctx context.Context, rw http.ResponseWriter, r *http.R
1107
1106
1108
1107
roles = append (roles , role )
1109
1108
}
1110
- return roles , true
1109
+ return roles , nil
1111
1110
}
1112
1111
1113
1112
// claimFields returns the sorted list of fields in the claims map.
0 commit comments