MCPcopy Index your code
hub / github.com/alexrudd/cognito-srp

github.com/alexrudd/cognito-srp @v4.1.0

Chat with this repo
repository ↗ · DeepWiki ↗ · release v4.1.0 ↗ · + Follow
34 symbols 119 edges 2 files 9 documented · 26%
What it actually does AI analysis from the code graph — generated when you open this
loading…
README

cognito-srp

Build Status Go Report Card Maintainability Test Coverage

This is almost a direct port of capless/warrant

All crypto functions are tested against equivalent values produced by warrant

  • v2 - Removed dependency on aws-sdk-go-v2
  • v3 - Migrate to map[string]*string types for better compatability with aws-sdk-go-v2
  • v4 - Migrate back to map[string]string types as aws-sdk-go-v2 reverted their API changes

Usage

package main

import (
    "context"
    "fmt"
    "time"

    cognitosrp "github.com/alexrudd/cognito-srp/v4"

    "github.com/aws/aws-sdk-go-v2/aws"
    "github.com/aws/aws-sdk-go-v2/config"
    cip "github.com/aws/aws-sdk-go-v2/service/cognitoidentityprovider"
    "github.com/aws/aws-sdk-go-v2/service/cognitoidentityprovider/types"
)

func main() {
    // configure cognito srp
    csrp, _ := cognitosrp.NewCognitoSRP("user", "pa55w0rd", "eu-west-1_myPoolId", "client", nil)

    // configure cognito identity provider
    cfg, _ := config.LoadDefaultConfig(
        config.WithRegion("eu-west-1"),
        config.WithCredentialsProvider(aws.AnonymousCredentials{}),
    )
    svc := cip.NewFromConfig(cfg)

    // initiate auth
    resp, err := svc.InitiateAuth(context.Background(), &cip.InitiateAuthInput{
        AuthFlow:       types.AuthFlowTypeUserSrpAuth,
        ClientId:       aws.String(csrp.GetClientId()),
        AuthParameters: csrp.GetAuthParams(),
    })
    if err != nil {
        panic(err)
    }

    // respond to password verifier challenge
    if resp.ChallengeName == types.ChallengeNameTypePasswordVerifier {
        challengeResponses, _ := csrp.PasswordVerifierChallenge(resp.ChallengeParameters, time.Now())

        resp, err := svc.RespondToAuthChallenge(context.Background(), &cip.RespondToAuthChallengeInput{
            ChallengeName:      types.ChallengeNameTypePasswordVerifier,
            ChallengeResponses: challengeResponses,
            ClientId:           aws.String(csrp.GetClientId()),
        })
        if err != nil {
            panic(err)
        }

        // print the tokens
        fmt.Printf("Access Token: %s\n", *resp.AuthenticationResult.AccessToken)
        fmt.Printf("ID Token: %s\n", *resp.AuthenticationResult.IdToken)
        fmt.Printf("Refresh Token: %s\n", *resp.AuthenticationResult.RefreshToken)
    } else {
        // other challenges await...
    }
}

Core symbols most depended-on inside this repo

hexToBig
called by 10
cognitosrp.go
NewCognitoSRP
called by 8
cognitosrp.go
padHex
called by 8
cognitosrp.go
calculateA
called by 6
cognitosrp.go
GetUsername
called by 5
cognitosrp.go
GetSecretHash
called by 4
cognitosrp.go
hexHash
called by 4
cognitosrp.go
hashSha256
called by 3
cognitosrp.go

Shape

Function 23
Method 10
Struct 1

Languages

Go100%

Modules by API surface

cognitosrp.go20 symbols
cognitosrp_test.go14 symbols

For agents

$ claude mcp add cognito-srp \
  -- python -m otcore.mcp_server <graph>

⬇ download graph artifact

Ask about this repo answers extend the page