handoff

package
v1.12.0 Latest Latest
Warning

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

Go to latest
Published: Nov 14, 2026 License: MIT Imports: 13 Imported by: 0

Documentation

Overview

Package handoff hands a session minted at an identity provider callback to the frontend that started the sign-in, by a single-use one-time code.

The callback is a top-level browser navigation landing on the API origin, so it cannot give tokens to an app that keeps them on its own origin. It stashes a reference to the session under a random code instead and redirects with `code=`. The app redeems the code once, with its publishable key, and gets a rotated token pair: the code names the session and carries no credential, so a copy of the ceremony store yields nothing a browser could present. The SSO and social plugins both use it.

Index

Constants

View Source
const TTL = 60 * time.Second

TTL is how long a code stays redeemable. The browser redeems it on the page the callback redirects to, so a minute is plenty.

Variables

This section is empty.

Functions

func Mint

func Mint(ctx context.Context, store ceremony.Store, prefix string, p *Payload) (string, error)

Mint stashes p under a fresh code in the namespace prefix (e.g. "sso:otc:") and returns the code.

Types

type Payload

type Payload struct {
	User      json.RawMessage `json:"user,omitempty"`
	SessionID string          `json:"session_id"`
	Provider  string          `json:"provider,omitempty"`
	IsNewUser bool            `json:"is_new_user,omitempty"`
	AppID     string          `json:"app_id"`
}

Payload is what a code stands for. It names the session and carries no token.

func Redeem

func Redeem(ctx forge.Context, eng *authsome.Engine, store ceremony.Store, prefix, code string) (*Payload, *session.Session, error)

Redeem spends code once and rotates the session it names. The caller's publishable-key app, when there is one, must be the app the code was minted for. Every failure is a 400 that says no more than that the code is no good, so a guess learns nothing.

Single use holds across replicas: a claim marker set with SetNX lets exactly one redeemer through even if two read the payload at once.

Jump to

Keyboard shortcuts

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