Skip to content

Commit

Permalink
Fix OIDC logout redirect uri (kubesphere#6348)
Browse files Browse the repository at this point in the history
* fix: oidc logout redirect uri

Signed-off-by: peng wu <[email protected]>

* fix: oidc unittest

Signed-off-by: peng wu <[email protected]>

---------

Signed-off-by: peng wu <[email protected]>
  • Loading branch information
smartcat999 authored Feb 5, 2025
1 parent 7ce92c8 commit f390d46
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
16 changes: 16 additions & 0 deletions pkg/apiserver/authentication/identityprovider/oidc/oidc.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (
"fmt"
"io"
"net/http"
"net/url"

"github.com/coreos/go-oidc/v3/oidc"

Expand Down Expand Up @@ -52,6 +53,10 @@ type oidcProvider struct {
// Scope specifies optional requested permissions.
Scopes []string `json:"scopes" yaml:"scopes"`

// Redirection to RP After Logout
// See https://openid.net/specs/openid-connect-rpinitiated-1_0.html#RedirectionAfterLogout
PostLogoutRedirectURI string `json:"postLogoutRedirectURI" yaml:"postLogoutRedirectURI"`

// GetUserInfo uses the userinfo endpoint to get additional claims for the token.
// This is especially useful where upstreams return "thin" id tokens
// See also, https://openid.net/specs/openid-connect-core-1_0.html#UserInfo
Expand Down Expand Up @@ -153,6 +158,17 @@ func (f *oidcProviderFactory) Create(opts options.DynamicOptions) (identityprovi
oidcProvider.Endpoint.UserInfoURL, _ = providerJSON["userinfo_endpoint"].(string)
oidcProvider.Endpoint.JWKSURL, _ = providerJSON["jwks_uri"].(string)
oidcProvider.Endpoint.EndSessionURL, _ = providerJSON["end_session_endpoint"].(string)

endSessionUrl, err := url.Parse(oidcProvider.Endpoint.EndSessionURL)
if err != nil {
return nil, fmt.Errorf("failed to parse end session url: %v", err)
}
endSessionQuery := endSessionUrl.Query()
endSessionQuery.Add("post_logout_redirect_uri", oidcProvider.PostLogoutRedirectURI)
endSessionQuery.Add("client_id", oidcProvider.ClientID)
endSessionUrl.RawQuery = endSessionQuery.Encode()

oidcProvider.Endpoint.EndSessionURL = endSessionUrl.String()
oidcProvider.Provider = provider
oidcProvider.Verifier = provider.Verifier(&oidc.Config{
// TODO: support HS256
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ var _ = Describe("OIDC", func() {
"tokenURL": fmt.Sprintf("%s/token", oidcServer.URL),
"userInfoURL": fmt.Sprintf("%s/userinfo", oidcServer.URL),
"jwksURL": fmt.Sprintf("%s/keys", oidcServer.URL),
"endSessionURL": fmt.Sprintf("%s/endsession", oidcServer.URL),
"endSessionURL": fmt.Sprintf("%s/endsession?client_id=kubesphere&post_logout_redirect_uri=", oidcServer.URL),
},
}
Expect(config).Should(Equal(expected))
Expand Down

0 comments on commit f390d46

Please sign in to comment.