Skip to content

Commit b3d370b

Browse files
committed
A few minor changes
1 parent bceb39c commit b3d370b

File tree

2 files changed

+10
-7
lines changed

2 files changed

+10
-7
lines changed

clients/authcode.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ func (c *authCode) GenerateAccessToken(client_id, client_secret, scopes string,
5757
return nil, err
5858
}
5959

60+
// TODO work and get error in returned code
6061
returnedURL, err := c.util.ReadLine("Enter the link you were redirected to after authorization", false)
6162
if err != nil {
6263
return nil, fmt.Errorf("error reading redirect URL: %w", err)
@@ -80,6 +81,7 @@ func (c *authCode) GenerateAccessToken(client_id, client_secret, scopes string,
8081
"code": {code},
8182
"client_id": {client_id},
8283
"client_secret": {client_secret},
84+
"redirect_uri": {c.redirectURL},
8385
}
8486
r := &http.Request{
8587
Method: "POST",
@@ -96,7 +98,7 @@ func (c *authCode) GenerateAccessToken(client_id, client_secret, scopes string,
9698
if resp.StatusCode != http.StatusOK {
9799
var errResp errorResponse
98100
if err := json.NewDecoder(resp.Body).Decode(&errResp); err != nil {
99-
return nil, fmt.Errorf("error decoding error response: %w", err)
101+
return nil, fmt.Errorf("status code: %s; error decoding error response: %w", resp.Status, err)
100102
}
101103
return nil, fmt.Errorf("%s - %s", errResp.Error, errResp.Description)
102104
}

main.go

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,26 +12,26 @@ import (
1212

1313
var (
1414
clientID = kingpin.Flag("client-id", "The client ID to be used in getting the access_token.").Required().String()
15-
clientSecret = kingpin.Flag("client-secret", "The client Secret to be used in the getting the access_token").Default("").String()
15+
clientSecret = kingpin.Flag("client-secret", "The client Secret to be used in the getting the access_token").String()
1616
scopes = kingpin.Flag("scopes", "The requested scopes").Required().String()
1717
customParams = kingpin.Flag("extra", "Extra params to be sent along with the client_id during authentication request").StringMap()
1818

1919
authCode = kingpin.Command("authcode", "Perform an authorization_code grant flow; https://oauth.net/2/grant-types/authorization-code/")
2020
authCodeURL = authCode.Arg("auth_url", "The URL that will be used for the authorization code generation").Required().String()
21-
tokenURL = authCode.Arg("token_url", "The URL to be used in token generation").Default("").String()
22-
authCodeRedirectURLFLag = authCode.Flag("redirect_url", "Redirect URL to be passed with the request").Default("").String()
21+
tokenURL = authCode.Arg("token_url", "The URL to be used in token generation").String()
22+
authCodeRedirectURLFLag = authCode.Flag("redirect_url", "Redirect URL to be passed with the request").String()
2323

2424
client_credentials = kingpin.Command("client_credentials", "Perform client_credential grant flow; https://oauth.net/2/grant-types/client-credentials/")
2525
clienCredsURL = client_credentials.Arg("auth_url", "URL for generating client credential based access token").Required().String()
2626

2727
implicitGrant = kingpin.Command("implicit", "Perform (Legacy) implicit grant type; https://oauth.net/2/grant-types/implicit/")
2828
implicitURL = implicitGrant.Arg("auth_url", "URL for generating implicit access_token").Required().String()
29-
implicitRedirectURLFlag = implicitGrant.Flag("redirect_url", "Redirect URL to be passed with the request").Default("").String()
29+
implicitRedirectURLFlag = implicitGrant.Flag("redirect_url", "Redirect URL to be passed with the request").String()
3030

3131
passwordGrant = kingpin.Command("password", "Perform (Legacy) password grant type; https://oauth.net/2/grant-types/password/")
3232
passwordURL = passwordGrant.Arg("auth_url", "URL for generatining password flow access_token").Required().String()
3333
usernameFlag = passwordGrant.Flag("username", "Username for authorization").Required().String()
34-
passwordFlag = passwordGrant.Flag("password", "User password").Default("").String()
34+
passwordFlag = passwordGrant.Flag("password", "User password").String()
3535
)
3636

3737
func main() {
@@ -59,8 +59,9 @@ func main() {
5959
token, err := client.GenerateAccessToken(*clientID, clientSecretValue, *scopes, *customParams)
6060
if err != nil {
6161
utils.PrintError(err)
62+
os.Exit(1)
6263
}
63-
fmt.Printf("token is: %s", token.AccessToken)
64+
fmt.Printf("token is: %s\n", token.AccessToken)
6465
}
6566

6667
func validateClientSecret(util *utils.MainUtil) (string, error) {

0 commit comments

Comments
 (0)