Help us shape the future of Go! Take the 2026 Go Developer Survey

magiclink

package
v0.7.0 Latest Latest
Warning

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

Go to latest
Published: Oct 30, 2026 License: MIT Imports: 14 Imported by: 0

Documentation

Overview

Package magiclink implements sign-in through an emailed one-time link.

The plugin uses only the public plugin package. It receives no privileged access to Auth-All internals, so a third-party plugin can do the same work.

Index

Constants

View Source
const DefaultTTL = 15 * time.Minute

DefaultTTL is the default lifetime of a sign-in link.

View Source
const ID = "magic-link"

ID is the stable plugin identifier.

View Source
const TokenKind = "magic-link"

TokenKind is the one-time token namespace of this plugin.

Variables

This section is empty.

Functions

This section is empty.

Types

type Option

type Option func(*Plugin)

Option configures the plugin.

func WithCallbackURL

func WithCallbackURL(v string) Option

WithCallbackURL sets where the browser goes after a successful sign-in. The default is the configured base URL.

func WithCreateUser

func WithCreateUser(v bool) Option

WithCreateUser controls whether an unknown address creates an account. It is enabled by default, because a magic link proves ownership of the address.

func WithTTL

func WithTTL(d time.Duration) Option

WithTTL sets the lifetime of a sign-in link.

func WithVerifyURL

func WithVerifyURL(v string) Option

WithVerifyURL overrides the absolute link that the email carries. The default is the verify endpoint of this plugin.

func WithoutConfirmation

func WithoutConfirmation() Option

WithoutConfirmation lets GET /magic-link/verify complete the sign-in on its own. The default needs the confirmation step.

Do not use this option unless you accept three risks. An attacker can make the browser of another person open a link and sign that person in to the account of the attacker. The token reaches the callback host through the Referer header. A mail scanner that pre-fetches the link consumes the token, so the person can no longer sign in.

type Plugin

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

Plugin is the Magic Link plugin.

func New

func New(opts ...Option) *Plugin

New returns the Magic Link plugin.

func (*Plugin) ID

func (p *Plugin) ID() string

ID implements plugin.Plugin.

func (*Plugin) Register

func (p *Plugin) Register(r *plugin.Registry) error

Register implements plugin.Plugin.

func (*Plugin) Send added in v0.6.0

func (p *Plugin) Send(ctx context.Context, r *http.Request, address, callbackURL string) error

Send sends a sign-in link to an address. It does the work of POST /magic-link/send, so a server-rendered form can send a link from its own handler and render its own confirmation.

Send applies the magic-link-request rate limit and returns apierr.ErrRateLimited when the limit refuses the request. It returns nil in every other case, including an invalid address and an unknown address when account creation is off, so the caller discloses nothing about the account.

r is the request of the host form. Send reads the client IP from it for the rate limit, and it runs the origin check on it, so a forged cross-site form fails with apierr.ErrOriginNotAllowed. A nil request skips the origin check, and the rate limit then keys on the address only.

callbackURL is where the browser goes after the sign-in. It passes the same safe-redirect check as the route, and an empty value takes the configured callback.

Jump to

Keyboard shortcuts

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