Skip to content

Commit

Permalink
Add native support to token V2
Browse files Browse the repository at this point in the history
  • Loading branch information
wpjunior committed Apr 3, 2024
1 parent c3a7c20 commit fe8da98
Showing 1 changed file with 17 additions and 2 deletions.
19 changes: 17 additions & 2 deletions pkg/client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,23 @@ func ClientFromEnvironment(cfg *tsuru.Configuration) (*tsuru.APIClient, error) {
cfg.DefaultHeader = map[string]string{}
}
if _, authSet := cfg.DefaultHeader["Authorization"]; !authSet {
// TODO: use transport instead of token v1
if token, tokenErr := config.ReadTokenV1(); tokenErr == nil && token != "" {
tokenV2, err := config.ReadTokenV2()
if err != nil {
return nil, err
}

teamToken := config.ReadTeamToken()
if tokenV2 != nil && tokenV2.Scheme == "oidc" && teamToken == "" {
oidcTokenSource := NewOIDCTokenSource(tokenV2)
config.DefaultTokenProvider = &OIDCTokenProvider{OAuthTokenSource: oidcTokenSource}

cfg.HTTPClient = &http.Client{
Transport: &oauth2.Transport{
Base: http.DefaultTransport,
Source: oidcTokenSource,
},
}
} else if token, tokenErr := config.ReadTokenV1(); tokenErr == nil && token != "" {
cfg.DefaultHeader["Authorization"] = "bearer " + token
}
}
Expand Down

0 comments on commit fe8da98

Please sign in to comment.