@@ -669,7 +669,7 @@ func (api *API) userOAuth2Github(rw http.ResponseWriter, r *http.Request) {
669
669
})
670
670
cookies , user , key , err := api .oauthLogin (r , params )
671
671
defer params .CommitAuditLogs ()
672
- var httpErr idpsync.HttpError
672
+ var httpErr idpsync.HTTPError
673
673
if xerrors .As (err , & httpErr ) {
674
674
httpErr .Write (rw , r )
675
675
return
@@ -1069,7 +1069,7 @@ func (api *API) userOIDC(rw http.ResponseWriter, r *http.Request) {
1069
1069
})
1070
1070
cookies , user , key , err := api .oauthLogin (r , params )
1071
1071
defer params .CommitAuditLogs ()
1072
- var httpErr idpsync.HttpError
1072
+ var httpErr idpsync.HTTPError
1073
1073
if xerrors .As (err , & httpErr ) {
1074
1074
httpErr .Write (rw , r )
1075
1075
return
@@ -1097,7 +1097,7 @@ func (api *API) userOIDC(rw http.ResponseWriter, r *http.Request) {
1097
1097
}
1098
1098
1099
1099
// oidcGroups returns the groups for the user from the OIDC claims.
1100
- func (api * API ) oidcGroups (ctx context.Context , mergedClaims map [string ]interface {}) (bool , []string , * idpsync.HttpError ) {
1100
+ func (api * API ) oidcGroups (ctx context.Context , mergedClaims map [string ]interface {}) (bool , []string , * idpsync.HTTPError ) {
1101
1101
logger := api .Logger .Named (userAuthLoggerName )
1102
1102
usingGroups := false
1103
1103
var groups []string
@@ -1118,7 +1118,7 @@ func (api *API) oidcGroups(ctx context.Context, mergedClaims map[string]interfac
1118
1118
slog .F ("type" , fmt .Sprintf ("%T" , groupsRaw )),
1119
1119
slog .Error (err ),
1120
1120
)
1121
- return false , nil , & idpsync.HttpError {
1121
+ return false , nil , & idpsync.HTTPError {
1122
1122
Code : http .StatusBadRequest ,
1123
1123
Msg : "Failed to sync groups from OIDC claims" ,
1124
1124
Detail : err .Error (),
@@ -1151,7 +1151,7 @@ func (api *API) oidcGroups(ctx context.Context, mergedClaims map[string]interfac
1151
1151
if len (groups ) == 0 {
1152
1152
detail = "You are currently not a member of any groups! Ask an administrator to add you to an authorized group to login."
1153
1153
}
1154
- return usingGroups , groups , & idpsync.HttpError {
1154
+ return usingGroups , groups , & idpsync.HTTPError {
1155
1155
Code : http .StatusForbidden ,
1156
1156
Msg : "Not a member of an allowed group" ,
1157
1157
Detail : detail ,
@@ -1175,7 +1175,7 @@ func (api *API) oidcGroups(ctx context.Context, mergedClaims map[string]interfac
1175
1175
// It would be preferred to just return an error, however this function
1176
1176
// decorates returned errors with the appropriate HTTP status codes and details
1177
1177
// that are hard to carry in a standard `error` without more work.
1178
- func (api * API ) oidcRoles (ctx context.Context , mergedClaims map [string ]interface {}) ([]string , * idpsync.HttpError ) {
1178
+ func (api * API ) oidcRoles (ctx context.Context , mergedClaims map [string ]interface {}) ([]string , * idpsync.HTTPError ) {
1179
1179
roles := api .OIDCConfig .UserRolesDefault
1180
1180
if ! api .OIDCConfig .RoleSyncEnabled () {
1181
1181
return roles , nil
@@ -1197,7 +1197,7 @@ func (api *API) oidcRoles(ctx context.Context, mergedClaims map[string]interface
1197
1197
slog .F ("type" , fmt .Sprintf ("%T" , rolesRow )),
1198
1198
slog .Error (err ),
1199
1199
)
1200
- return nil , & idpsync.HttpError {
1200
+ return nil , & idpsync.HTTPError {
1201
1201
Code : http .StatusInternalServerError ,
1202
1202
Msg : "Login disabled until OIDC config is fixed" ,
1203
1203
Detail : fmt .Sprintf ("Roles claim must be an array of strings, type found: %T. Disabling role sync will allow login to proceed." , rolesRow ),
@@ -1358,7 +1358,7 @@ func (api *API) oauthLogin(r *http.Request, params *oauthLoginParams) ([]*http.C
1358
1358
if api .OIDCConfig != nil && api .OIDCConfig .SignupsDisabledText != "" {
1359
1359
signupsDisabledText = render .HTMLFromMarkdown (api .OIDCConfig .SignupsDisabledText )
1360
1360
}
1361
- return & idpsync.HttpError {
1361
+ return & idpsync.HTTPError {
1362
1362
Code : http .StatusForbidden ,
1363
1363
Msg : "Signups are disabled" ,
1364
1364
Detail : signupsDisabledText ,
@@ -1409,7 +1409,7 @@ func (api *API) oauthLogin(r *http.Request, params *oauthLoginParams) ([]*http.C
1409
1409
}
1410
1410
}
1411
1411
if ! validUsername {
1412
- return & idpsync.HttpError {
1412
+ return & idpsync.HTTPError {
1413
1413
Code : http .StatusConflict ,
1414
1414
Msg : fmt .Sprintf ("exhausted alternatives for taken username %q" , original ),
1415
1415
}
@@ -1564,7 +1564,7 @@ func (api *API) oauthLogin(r *http.Request, params *oauthLoginParams) ([]*http.C
1564
1564
//nolint:gocritic
1565
1565
err := api .Options .SetUserSiteRoles (dbauthz .AsSystemRestricted (ctx ), logger , tx , user .ID , filtered )
1566
1566
if err != nil {
1567
- return & idpsync.HttpError {
1567
+ return & idpsync.HTTPError {
1568
1568
Code : http .StatusBadRequest ,
1569
1569
Msg : "Invalid roles through OIDC claims" ,
1570
1570
Detail : fmt .Sprintf ("Error from role assignment attempt: %s" , err .Error ()),
@@ -1679,15 +1679,15 @@ func (api *API) convertUserToOauth(ctx context.Context, r *http.Request, db data
1679
1679
// Trying to convert to OIDC, but the email does not match.
1680
1680
// So do not make a new user, just block the request.
1681
1681
if user .ID == uuid .Nil {
1682
- return database.User {}, idpsync.HttpError {
1682
+ return database.User {}, idpsync.HTTPError {
1683
1683
Code : http .StatusBadRequest ,
1684
1684
Msg : fmt .Sprintf ("The oidc account with the email %q does not match the email of the account you are trying to convert. Contact your administrator to resolve this issue." , params .Email ),
1685
1685
}
1686
1686
}
1687
1687
1688
1688
jwtCookie , err := r .Cookie (OAuthConvertCookieValue )
1689
1689
if err != nil {
1690
- return database.User {}, idpsync.HttpError {
1690
+ return database.User {}, idpsync.HTTPError {
1691
1691
Code : http .StatusBadRequest ,
1692
1692
Msg : fmt .Sprintf ("Convert to oauth cookie not found. Missing signed jwt to authorize this action. " +
1693
1693
"Please try again." ),
@@ -1699,13 +1699,13 @@ func (api *API) convertUserToOauth(ctx context.Context, r *http.Request, db data
1699
1699
})
1700
1700
if xerrors .Is (err , jwt .ErrSignatureInvalid ) || ! token .Valid {
1701
1701
// These errors are probably because the user is mixing 2 coder deployments.
1702
- return database.User {}, idpsync.HttpError {
1702
+ return database.User {}, idpsync.HTTPError {
1703
1703
Code : http .StatusBadRequest ,
1704
1704
Msg : "Using an invalid jwt to authorize this action. Ensure there is only 1 coder deployment and try again." ,
1705
1705
}
1706
1706
}
1707
1707
if err != nil {
1708
- return database.User {}, idpsync.HttpError {
1708
+ return database.User {}, idpsync.HTTPError {
1709
1709
Code : http .StatusInternalServerError ,
1710
1710
Msg : fmt .Sprintf ("Error parsing jwt: %v" , err ),
1711
1711
}
@@ -1727,14 +1727,14 @@ func (api *API) convertUserToOauth(ctx context.Context, r *http.Request, db data
1727
1727
oauthConvertAudit .Old = user
1728
1728
1729
1729
if claims .RegisteredClaims .Issuer != api .DeploymentID {
1730
- return database.User {}, idpsync.HttpError {
1730
+ return database.User {}, idpsync.HTTPError {
1731
1731
Code : http .StatusForbidden ,
1732
1732
Msg : "Request to convert login type failed. Issuer mismatch. Found a cookie from another coder deployment, please try again." ,
1733
1733
}
1734
1734
}
1735
1735
1736
1736
if params .State .StateString != claims .State {
1737
- return database.User {}, idpsync.HttpError {
1737
+ return database.User {}, idpsync.HTTPError {
1738
1738
Code : http .StatusForbidden ,
1739
1739
Msg : "Request to convert login type failed. State mismatch." ,
1740
1740
}
@@ -1746,7 +1746,7 @@ func (api *API) convertUserToOauth(ctx context.Context, r *http.Request, db data
1746
1746
if user .ID != claims .UserID ||
1747
1747
codersdk .LoginType (user .LoginType ) != claims .FromLoginType ||
1748
1748
codersdk .LoginType (params .LoginType ) != claims .ToLoginType {
1749
- return database.User {}, idpsync.HttpError {
1749
+ return database.User {}, idpsync.HTTPError {
1750
1750
Code : http .StatusForbidden ,
1751
1751
Msg : fmt .Sprintf ("Request to convert login type from %s to %s failed" , user .LoginType , params .LoginType ),
1752
1752
}
@@ -1762,7 +1762,7 @@ func (api *API) convertUserToOauth(ctx context.Context, r *http.Request, db data
1762
1762
UserID : user .ID ,
1763
1763
})
1764
1764
if err != nil {
1765
- return database.User {}, idpsync.HttpError {
1765
+ return database.User {}, idpsync.HTTPError {
1766
1766
Code : http .StatusInternalServerError ,
1767
1767
Msg : "Failed to convert user to new login type" ,
1768
1768
}
@@ -1850,12 +1850,12 @@ func clearOAuthConvertCookie() *http.Cookie {
1850
1850
}
1851
1851
}
1852
1852
1853
- func wrongLoginTypeHTTPError (user database.LoginType , params database.LoginType ) idpsync.HttpError {
1853
+ func wrongLoginTypeHTTPError (user database.LoginType , params database.LoginType ) idpsync.HTTPError {
1854
1854
addedMsg := ""
1855
1855
if user == database .LoginTypePassword {
1856
1856
addedMsg = " You can convert your account to use this login type by visiting your account settings."
1857
1857
}
1858
- return idpsync.HttpError {
1858
+ return idpsync.HTTPError {
1859
1859
Code : http .StatusForbidden ,
1860
1860
RenderStaticPage : true ,
1861
1861
Msg : "Incorrect login type" ,
0 commit comments