stytch-go

module
v3.0.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 29, 2021 License: MIT

README

stytch-go

A Go client library for the Stytch API.

Table of Contents

Install

$ go get github.com/stytchauth/stytch-go/v3

Documentation

The module supports all Stytch API endpoints. Full documentation can be found here.

Getting Started

Calling Endpoints

To call an endpoint you must first create a Stytch API object.

import (
	"os"

	"github.com/stytchauth/stytch-go/stytch"
	"github.com/stytchauth/stytch-go/stytch/stytchapi"
)

stytchAPIClient := stytchapi.NewAPIClient(
	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.

Users - Create
	res, err := stytchAPIClient.Users.Create(&stytch.UsersCreateParams{
		Email:      "sandbox@stytch.com",
		Name: stytch.Name{
			FirstName:  "Clark",
			MiddleName: "Joseph",
			LastName:   "Kent",
		},
	})
Users - Get
	res, err := stytchAPIClient.Users.Get("user-test-e3ca2fde-0cbe-4248-a8b8-b1dd68a4514d")
	res, err := stytchAPIClient.MagicLinks.Email.Send(&stytch.MagicLinksEmailSendParams{
		Email:              "sandbox@stytch.com",
		LoginMagicLinkURL:  "https://example.com/login",
		SignupMagicLinkURL: "https://example.com/signup",
		Attributes:         stytch.Attributes{
			IPAddress: "10.0.0.0",
		},
    })
	res, err := stytchAPIClient.MagicLinks.Authenticate(
		&stytch.MagicLinksAuthenticateParams{
			Token:      "GCRzBlufdaQ3mJh2QcygLsbuG__gqGwwvRuIuetv6ZM=",
			Options:    stytch.Options{IPMatchRequired: true},
			Attributes: stytch.Attributes{IPAddress: "10.0.0.0"},
		})
	res, err := stytchAPIClient.MagicLinks.Email.LoginOrCreate(&stytch.MagicLinksEmailLoginOrCreateParams{
		Email:                  "sandbox@stytch.com",
		LoginMagicLinkURL:      "https://example.com/login",
		SignupMagicLinkURL:     "https://example.com/signup",
		Attributes:             stytch.Attributes{
			IPAddress: "10.0.0.0",
		},
	})
	res, err := stytchAPIClient.MagicLinks.Email.Invite(&stytch.MagicLinksEmailInviteParams{
		Email:                   "sandbox@stytch.com",
		InviteMagicLinkURL:      "https://example.com/invite",
		Attributes:              stytch.Attributes{
			IPAddress: "10.0.0.0",
		},
	})
	res, err := stytchAPIClient.MagicLinks.Email.RevokeInvite(&stytch.MagicLinksEmailRevokeInviteParams{
		Email: "sandbox@stytch.com"
	})
Users - Get Pending
	res, err := stytchAPIClient.Users.GetPending()
Errors

All non-200 responses will return a stytch.Error instance.

For more information on Stytch response codes, head to the docs.

Developing

  1. Download this repo into your Go source directory
  2. Run make setup pull down all dependencies etc

Support

Open an issue!

License

MIT

Directories

Path Synopsis
otp

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL