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
- An initial request to the login endpoint is made with a user's email address in the creds map.
- A signed JWT is created and emailed to the user.
- The user clicks the link, which makes a request back to the login endpoint with the JWT in the URL
- 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 ¶
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.