Skip to content

Commit

Permalink
adds readme and changes session init for AWS
Browse files Browse the repository at this point in the history
  • Loading branch information
RafPe committed Nov 26, 2018
1 parent f05582f commit 35fc249
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 12 deletions.
47 changes: 46 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,47 @@
# go-cognito-authy
Congito User Pool quick auth CLI for testing purposes
Congito User Pool quick auth CLI for testing purposes.

# Examples
First create user(s) in Cognito Pool ( or import them ) and then use one of commands below

## Authenticate
Try to authenticate using `myAwsProfile` profile and `eu-central-1` as region
```
go-cognito-authy -profile myAwsProfile -region eu-central-1 auth --username <username-in-pool> --password '<some-magical-password>' --clientID <app-client-id>
```

Received response with tokens
```
> [SHELL] RafPe $ go-cognito-authy --profile cloudy --region eu-central-1 auth --username rafpe --password 'Password.0ne!' --clientID 2jxxxiuui123
{
AuthenticationResult: {
AccessToken: "eyJraWQiOiJ0QXVBNmxtNngrYkxoSmZ",
ExpiresIn: 3600,
IdToken: "eyJraWQiOiJ0bHF2UElTV0pn",
RefreshToken: "eyJjdHkiOiJKV1QiLCJlbmMiOiJBMjU2R-TpkR_uompG7fyajYeFvn-rJVC_tDO4pB3",
TokenType: "Bearer"
},
ChallengeParameters: {}
}
```

Received response with challenge ( if it was NEW_PASSWORD_REQUIRED then I would admin reset my pass ;) )
```
> [INSERT] RafPe $ go-cognito-authy --profile cloudy --region eu-central-1 auth --username rafpe --password 'Password.0ne!' --clientID 2jxxxiuui123
{
ChallengeName: "NEW_PASSWORD_REQUIRED",
ChallengeParameters: {
requiredAttributes: "[]",
userAttributes: "{\"email_verified\":\"true\",\"email\":\"[email protected]\"}",
USER_ID_FOR_SRP: "rafpe"
},
Session: "bCqSkLeoJR_ys...."
}
```

## Admin
Administrative actions
* Reset password
```
> [INSERT] RafPe $ go-cognito-authy --profile cloudy -region eu-central-1 admin reset-pass --username rafpe --pass-new 'Password.0ne2!' --clientID 2jxxxiuui123 --userPoolID eu-central-1_CWNnTiR0j --session "bCqSkLeoJR_ys...."
```
22 changes: 11 additions & 11 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,17 @@ func main() {
app.Before = func(c *cli.Context) error {
var sesErr error

if c.String("profile") != "-" {

switch c.String("profile") {
case "-", "":
ses, sesErr = session.NewSession(&aws.Config{
Region: aws.String(c.String("region")),
Credentials: credentials.NewStaticCredentials(c.String("access-key"), c.String("secret-key"), ""),
})
if sesErr != nil {
fmt.Println(sesErr)
os.Exit(1)
}
default:
sessionParams = session.Options{
Profile: c.String("profile"),
Config: aws.Config{Region: aws.String(c.String("region"))},
Expand All @@ -70,15 +79,6 @@ func main() {
}
}

ses, sesErr = session.NewSession(&aws.Config{
Region: aws.String(c.String("region")),
Credentials: credentials.NewStaticCredentials(c.String("access-key"), c.String("secret-key"), ""),
})
if sesErr != nil {
fmt.Println(sesErr)
os.Exit(1)
}

cip = cognitoidentityprovider.New(ses)

return nil
Expand Down

0 comments on commit 35fc249

Please sign in to comment.