Compare commits

...

3 Commits

Author SHA1 Message Date
Hidetake Iwata
30b84035d8 Fix lint error and refactor 2026-02-22 19:30:58 +09:00
Hidetake Iwata
356b42a0a3 Merge branch 'master' into redirect-url-path 2026-02-21 19:43:18 +09:00
9b25297bf0 Recognize path from redirect url in callback server 2026-01-09 23:25:35 +09:00

View File

@@ -3,6 +3,7 @@ package client
import (
"context"
"fmt"
"net/url"
gooidc "github.com/coreos/go-oidc/v3/oidc"
"github.com/int128/kubelogin/pkg/oidc"
@@ -42,17 +43,22 @@ func (c *client) NegotiatedPKCEMethod() pkce.Method {
// GetTokenByAuthCode performs the authorization code flow.
func (c *client) GetTokenByAuthCode(ctx context.Context, in GetTokenByAuthCodeInput, localServerReadyChan chan<- string) (*oidc.TokenSet, error) {
ctx = c.wrapContext(ctx)
parsedRedirectURL, err := url.Parse(c.oauth2Config.RedirectURL)
if err != nil {
return nil, fmt.Errorf("invalid redirect url: %w", err)
}
config := oauth2cli.Config{
OAuth2Config: c.oauth2Config,
State: in.State,
AuthCodeOptions: authorizationRequestOptions(in.Nonce, in.PKCEParams, in.AuthRequestExtraParams),
TokenRequestOptions: tokenRequestOptions(in.PKCEParams),
LocalServerBindAddress: in.BindAddress,
LocalServerReadyChan: localServerReadyChan,
LocalServerSuccessHTML: in.LocalServerSuccessHTML,
LocalServerCertFile: in.LocalServerCertFile,
LocalServerKeyFile: in.LocalServerKeyFile,
Logf: c.logger.V(1).Infof,
OAuth2Config: c.oauth2Config,
State: in.State,
AuthCodeOptions: authorizationRequestOptions(in.Nonce, in.PKCEParams, in.AuthRequestExtraParams),
TokenRequestOptions: tokenRequestOptions(in.PKCEParams),
LocalServerBindAddress: in.BindAddress,
LocalServerReadyChan: localServerReadyChan,
LocalServerSuccessHTML: in.LocalServerSuccessHTML,
LocalServerCallbackPath: parsedRedirectURL.Path,
LocalServerCertFile: in.LocalServerCertFile,
LocalServerKeyFile: in.LocalServerKeyFile,
Logf: c.logger.V(1).Infof,
}
token, err := oauth2cli.GetToken(ctx, config)
if err != nil {