Skip to content

Commit 3e2b3ec

Browse files
committed
Fix issues found when testing with auth0
1 parent 8699faf commit 3e2b3ec

File tree

4 files changed

+15
-5
lines changed

4 files changed

+15
-5
lines changed

cli/authcode_client_impersonator.go

+6
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ type AuthcodeClientImpersonator struct {
2222
config client.Config
2323
ClientID string
2424
ClientSecret string
25+
Audience string
2526
Scope string
2627
Port int
2728
Log Logger
@@ -49,6 +50,7 @@ func NewAuthcodeClientImpersonator(
4950
config client.Config,
5051
clientID string,
5152
clientSecret string,
53+
audience string,
5254
scope string,
5355
port int,
5456
log Logger,
@@ -59,6 +61,7 @@ func NewAuthcodeClientImpersonator(
5961
config: config,
6062
ClientID: clientID,
6163
ClientSecret: clientSecret,
64+
Audience: audience,
6265
Scope: scope,
6366
Port: port,
6467
BrowserLauncher: launcher,
@@ -98,6 +101,9 @@ func (aci AuthcodeClientImpersonator) Authorize() {
98101
requestValues := url.Values{}
99102
requestValues.Add("response_type", "code")
100103
requestValues.Add("client_id", aci.ClientID)
104+
if aci.Audience != "" {
105+
requestValues.Add("audience", aci.Audience)
106+
}
101107
requestValues.Add("redirect_uri", aci.redirectURI())
102108
requestValues.Add("scope", strings.Replace(aci.Scope, ",", " ", -1))
103109
requestValues.Add("state", uuid.New().String())

client/context.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,8 @@ type Target struct {
2222
}
2323

2424
type ClientContext struct {
25-
ClientID string `json:"client_id"`
25+
ClientID string `json:"client_id"`
26+
ClientSecret string `json:"client_secret"`
2627
Token
2728
}
2829

cmd/root.go

+1
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ var (
2424
var (
2525
scope string
2626
clientSecret string
27+
audience string
2728
port int
2829
force bool
2930
)

cmd/token.go

+6-4
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,8 @@ func refreshContext(contextName string, cfg client.Config, log cli.Logger) error
5454
return err
5555
}
5656
refreshClient := client.RefreshTokenClient{
57-
ClientID: context.ClientID,
57+
ClientID: context.ClientID,
58+
ClientSecret: context.ClientSecret,
5859
}
5960
token, err := refreshClient.RequestToken(HTTPClient(), cfg, context.Token.RefreshToken)
6061
if err != nil {
@@ -90,7 +91,7 @@ var getAuthcodeToken = &cobra.Command{
9091
}
9192
}
9293
} else {
93-
authCodeImp := cli.NewAuthcodeClientImpersonator(HTTPClient(), cfg, args[0], clientSecret, scope, port, log, open.Run)
94+
authCodeImp := cli.NewAuthcodeClientImpersonator(HTTPClient(), cfg, args[0], clientSecret, audience, scope, port, log, open.Run)
9495
go AuthcodeTokenCommandRun(done, args[0], authCodeImp, log)
9596
<-done
9697
}
@@ -99,8 +100,9 @@ var getAuthcodeToken = &cobra.Command{
99100

100101
func init() {
101102
getAuthcodeToken.Flags().IntVarP(&port, "port", "p", 8080, "port on which to run local callback server")
102-
getAuthcodeToken.Flags().StringVarP(&scope, "scope", "s", "openid,offline_access", "comma-separated scopes to request in token")
103-
getAuthcodeToken.Flags().StringVarP(&clientSecret, "client_secret", "c", "", "client secret")
103+
getAuthcodeToken.Flags().StringVarP(&scope, "scope", "s", "openid,offline_access", "comma-separated list of scopes, this will be used as the `scopes` query parameter when requesting the token.")
104+
getAuthcodeToken.Flags().StringVarP(&clientSecret, "client_secret", "c", "", "this will be used as the `client_secret` query parameter when requesting the token.")
105+
getAuthcodeToken.Flags().StringVarP(&audience, "audience", "a", "", "this will be used as the `audience` query parameter when requesting the token.")
104106

105107
getAuthcodeToken.Flags().BoolVarP(&force, "force", "f", false, "Forces a new token")
106108
tokenCmd.AddCommand(getAuthcodeToken)

0 commit comments

Comments
 (0)