https://github.com/rickh94/go-pa-client
Purple Auth client library for go
https://github.com/rickh94/go-pa-client
authentication golang passwordless security service web
Last synced: over 1 year ago
JSON representation
Purple Auth client library for go
- Host: GitHub
- URL: https://github.com/rickh94/go-pa-client
- Owner: rickh94
- License: mit
- Created: 2023-07-08T17:51:11.000Z (almost 3 years ago)
- Default Branch: main
- Last Pushed: 2023-07-12T16:29:32.000Z (almost 3 years ago)
- Last Synced: 2024-06-21T15:42:26.654Z (about 2 years ago)
- Topics: authentication, golang, passwordless, security, service, web
- Language: Go
- Homepage: https://purpleauth.com
- Size: 48.8 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Purple Auth Client (Go)
[](https://pkg.go.dev/pkgs.go.dev/github.com/rickh94/go-pa-client)
An async python client for my ["Purple Auth"
microservice](https://purpleauth.com).
The basics are outlined below, or you can [look at an example](https://github.com/rickh94/go-pa-client/tree/main/example)
### initialization
Create an account and application on [purpelauth.com](https://purpleauth.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.
```go
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.
```go
if err := client.Authenticate("test@example.com", "otp"); err != nil {
log.Fatal(err)
}
```
### /otp/confirm/
Complete authentication with email and generated code submitted by the user.
```go
token, err := client.SubmitCode("test@example.com", "123456")
```
### /token/verify/
Send idToken to server for verification.
```go
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
```go
newToken, err := client.Refresh(refreshTokenFromClient)
```
### /app/
Get more info about this app from the server.
```go
info = client.GetAppInfo()
```
### /magic/request/
Start authentication using magic link flow.
```go
if err := client.Authenticate("test@example.com", "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
```go
claims, err := client.VerifyToken(idTokenFromClient)
```