Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(auth): fix auth redirect bug #1925

Merged
merged 3 commits into from
May 13, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
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
6 changes: 5 additions & 1 deletion pkg/gateway/auth/login.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,11 @@ const RedirectURIKey = "redirect_uri"

// RedirectLogin to redirect the http request to login page.
func RedirectLogin(w http.ResponseWriter, r *http.Request, oauthConfig *oauth2.Config, disableOIDCProxy bool) {
oauthURL := oauthConfig.AuthCodeURL(r.URL.String(), oauth2.AccessTypeOffline)
state := r.URL.String()
if state == "" || state == "/" {
state = "/tkestack"
}
oauthURL := oauthConfig.AuthCodeURL(state, oauth2.AccessTypeOffline)
if !disableOIDCProxy {
originOAuthURL, err := url.Parse(oauthURL)
if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion pkg/gateway/token/token.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ func RetrieveToken(request *http.Request) (*Token, error) {
// OAuth2 token.
func ResponseToken(t *oauth2.Token, writer http.ResponseWriter) error {
idToken, ok := t.Extra("id_token").(string)
if !ok {
if !ok || idToken == "" {
log.Error("Failed to extra oauth2 token to id token", log.Any("token", t))
return fmt.Errorf("failed to extra oauth2 token to id token")
}
Expand Down