README ¶
stytch-go
A Go client library for the Stytch API.
Table of Contents
Install
$ go get github.com/stytchauth/stytch-go
Documentation
The module supports all Stytch API endpoints. Full documentation can be found here.
Getting Started
Calling Endpoints
To call an endpoint you must create a Client
object.
import (
"os"
"github.com/stytchauth/stytch-go/stytch"
)
stytchClient := stytch.NewClient(
stytch.EnvTest, // available environments are EnvTest and EnvLive
os.Getenv("STYTCH_PROJECT_ID"),
os.Getenv("STYTCH_SECRET"),
)
Each endpoint returns an object which contains the parsed JSON from the HTTP response.
Create User
res, err := stytchClient.CreateUser(&stytch.CreateUser{
Email: "clark@stytch.com",
Name: stytch.Name{
FirstName: "Clark",
MiddleName: "Joseph",
LastName: "Kent",
},
})
Get User
res, err := stytchClient.GetUser("user-test-e3ca2fde-0cbe-4248-a8b8-b1dd68a4514d")
Send Magic Link
res, err := sc.SendMagicLinkByEmail(&stytch.SendMagicLinkByEmail{
Email: "clark@stytch.com",
MagicLinkURL: "https://yoururl.com",
ExpirationMinutes: 5,
Attributes: stytch.Attributes{
IPAddress: "10.0.0.0",
},
})
Authenticate Magic Link
res, err := sc.AuthenticateMagicLink(
"GCRzBlufdaQ3mJh2QcygLsbuG__gqGwwvRuIuetv6ZM=",
&stytch.AuthenticateMagicLink{
Options: stytch.Options{IPMatchRequired: true},
Attributes: stytch.Attributes{IPAddress: "10.0.0.0"},
})
Login or Create A User
res, err := sc.LoginOrCreateUser(&stytch.LoginOrCreateUser{
Email: "clark@stytch.com",
LoginMagicLinkURL: "https://yoururl.com/login",
SignupMagicLinkURL: "https://yoururl.com/signup",
Attributes: stytch.Attributes{
IPAddress: "10.0.0.0",
},
})
Invite A User By Email
res, err := sc.InviteByEmail(&stytch.InviteByEmail{
Email: "clark@stytch.com",
MagicLinkURL: "https://yoururl.com/invite",
Attributes: stytch.Attributes{
IPAddress: "10.0.0.0",
},
})
Revoke an Invitation By Email
res, err := sc.RevokeInviteByEmail(&stytch.RevokeInviteByEmail{
Email: "clark@stytch.com"
})
Get Pending Users
res, err := sc.GetPendingUsers()
Errors
All non-200 responses will return a stytch.Error instance.
For more information on Stytch response codes, head to the docs.
Developing
- Download this repo into your Go source directory
- Run
make setup
pull down all dependencies etc
Support
Open an issue!
License
Click to show internal directories.
Click to hide internal directories.