Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions coderd/httpmw/oauth2.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,21 @@ func ExtractOAuth2(config OAuth2Config, client *http.Client) func(http.Handler)
return
}

// OIDC errors can be returned as query parameters. This can happen
// if for example we are providing and invalid scope.
// We should terminate the OIDC process if we encounter an error.
oidcError := r.URL.Query().Get("error")
errorDescription := r.URL.Query().Get("error_description")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Per the OIDC spec only the error response parameter is required; the error_description field is optional so we should handle that being blank.

Also there is an error_uri parameter that might be present so we should check for that as well.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I do handle an empty error_description. The Details part of the error is extra developer debug info. If it is empty, we provide no extra details, since we have no extra information.

I can add error_uri though 👍

if oidcError != "" {
oidcError = fmt.Sprintf("Encountered error in oidc process: %s", oidcError)
httpapi.Write(ctx, rw, http.StatusBadRequest, codersdk.Response{
Message: oidcError,
// errorDescription is optional.
Detail: errorDescription,
})
return
}

code := r.URL.Query().Get("code")
state := r.URL.Query().Get("state")

Expand Down