magiclink

package
v0.2.1 Latest Latest
Warning

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

Go to latest
Published: May 9, 2025 License: MIT Imports: 14 Imported by: 0

Documentation

Overview

Package magiclink provides passwordless authentication, allowing users to authenticate using a magic link that is sent to their email address.

### Configuration:

|---------------------------|---------------------------| | Env | JSON | | --------------------------|---------------------------| | AUTH_MAGICLINK_SIGNINGKEY | auth.magiclink.signingkey | | AUTH_MAGICLINK_EXPIRATION | auth.magiclink.expiration | | --------------------------|---------------------------|

### Basic Flow

  1. An initial request to the login endpoint is made with a user's email address in the creds map.
  2. A signed JWT is created and emailed to the user.
  3. The user clicks the link, which makes a request back to the login endpoint with the JWT in the URL
  4. If the JWT is valid, a cookie is set with an identity token that can be used to authenticate the user's identity.

Variation:

  • If the original login request has a `redirect_uri` parameter, then the magic link is constructed using the redirect URI. Once the user clicks through to the destination, the application can use the token to exchange for an identity token by using the login endpoint with an `issue_token` param.

TODO: Provide a way to prevent replay of magic links. TODO: Provide a way to rate-limit and/or block login requests.

Index

Constants

View Source
const (
	// Constant name for the Magic Link auth plugin.
	PluginName = "auth_magiclink"

	// Constant name used as the auth provider in API requests.
	ProviderName = "magiclink"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Claims

type Claims struct {
	jwt.RegisteredClaims
	Email       string `json:"email"`
	IssueToken  bool   `json:"it"`
	RedirectUri string `json:"ru"`
}

type MagicLinkOption

type MagicLinkOption func(*MagicLinkPlugin)

MagicLinkOptions allow configuration of the MagicLinkPlugin.

func WithExpiration

func WithExpiration(expiration time.Duration) MagicLinkOption

WithExpiration sets the expiration to use when signing magic link tokens.

func WithSigningKey

func WithSigningKey(signingKey []byte) MagicLinkOption

WithSigningKey sets the signing key to use when signing magic link tokens.

type MagicLinkPlugin

type MagicLinkPlugin struct {
	// contains filtered or unexported fields
}

Plugin for handling passwordless authentication via email.

func Plugin

func Plugin(opts ...MagicLinkOption) *MagicLinkPlugin

Plugin for handling passwordless authentication via email.

func (*MagicLinkPlugin) Deps

func (p *MagicLinkPlugin) Deps() []string

From prefab.DependentPlugin.

func (*MagicLinkPlugin) Init

From prefab.InitializablePlugin.

func (*MagicLinkPlugin) Name

func (p *MagicLinkPlugin) Name() string

From prefab.Plugin.

Jump to

Keyboard shortcuts

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