Go

Authenticate requests and manage Passage users with Go.

GitHub go.mod Go version (branch)

Prerequisites

Passage App ID and API Key from Passage Console

Install

Install the passage-go (opens in a new tab) package.

go get github.com/passageidentity/passage-go/v2

Initialize

import (
  "os"
 
  "github.com/passageidentity/passage-go/v2"
)
 
psg, err := passage.New(os.Getenv("PASSAGE_APP_ID"), os.Getenv("PASSAGE_API_KEY"))

Authenticating requests

The Passkey Complete Go SDK provides a way to validate JWT-authenticated requests. To learn more, see our full guide on JWTs.

func protectedRouteHandler(w http.ResponseWriter, r *http.Request) {
  // Get Passage Authorization token from the request header
  authHeader := r.Header.Get("Authorization")
  token := strings.TrimPrefix(authHeader, "Bearer ")
 
  // Validate JWT using Passage
  var userID string
  var err error
  userID, err = psg.Auth.ValidateJWT(token)
  if err != nil {
    // Token is invalid
  }
 
  // Token is valid
  var user *passage.PassageUser
  user, err = psg.User.Get(userID)
 
  fmt.Printf("%+v", user)
}

User management

In addition to authenticating requests, the Passkey Complete Go SDK also provides a way to securely manage users. These functions require authentication using a Passage API key. API keys can be managed in the Passage Console.

The functionality currently available on a user (opens in a new tab) is:

  • Get a user's information (including any defined user metadata fields)
  • Activate or deactivate a user (a deactivated user will not be able to log in)
  • Update a user's information (email address or phone number)
  • Revoke a user's refresh tokens
  • Delete a user
  • Create a user

User device management

The functionality currently available for a webauthn device (opens in a new tab) is:

  • List all devices for a user
  • Revoke a particular device from a user

Creating Magic Links

The Passkey Complete Go SDK can be used to generate custom Magic Links (opens in a new tab) for users, that can be embedded into any content medium. To learn more, see our full guide on Embedded Magic Links.

Go reference

Go Reference (opens in a new tab)

For complete documentation on passage-go functions and types, check out the Go documentation (opens in a new tab).