Skip to content

rickh94/go-pa-client

Repository files navigation

Purple Auth Client (Go)

Go Reference

An async python client for my "Purple Auth" microservice.

The basics are outlined below, or you can look at an example

initialization

Create an account and application on purpelauth.com, then initialize the client with those values. You should store the api key in an environment variable, but the app id is a public value, not a secret.

import (
    purpleauth "github.com/rick94/go-pa-client"
)

func main() {
    client := purpleauth.NewClient("https://purpleauth.com", "My-App-ID", "My-API-Key")
}

You will initially be limited to 500 authentications per app, but you can email me to have that increased.

Routes Covered

/otp/request/

Start otp authentication flow with server. This will send a one time code to the user's email.

if err := client.Authenticate("[email protected]", "otp"); err != nil {
    log.Fatal(err)
}

/otp/confirm/

Complete authentication with email and generated code submitted by the user.

token, err := client.SubmitCode("[email protected]", "123456")

/token/verify/

Send idToken to server for verification.

claims, err := client.VerifyTokenRemote(idTokenFromClient)

You should prefer to verify tokens locally using the VerifyToken function, but this is provided as a convenience and sanity check.

/token/refresh/

Request a new ID Token from the server using a refresh token

newToken, err := client.Refresh(refreshTokenFromClient)

/app/

Get more info about this app from the server.

info = client.GetAppInfo()

/magic/request/

Start authentication using magic link flow.

if err := client.Authenticate("[email protected]", "otp"); err != nil {
    log.Fatal(err)
}

Local Verification

Verify and decode an ID Token on directly in the app without having to call out every time

claims, err := client.VerifyToken(idTokenFromClient)