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

hanko

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Oct 12, 2026 License: Apache-2.0 Imports: 19 Imported by: 0

Documentation

Overview

Package hanko is the Hanko identity provider adapter. Hanko owns credentials and sessions: its <hanko-auth> element signs users in and stores the session token in the "hanko" cookie, and this adapter validates that token with Hanko on every request.

The Hanko tenant must allow account deletion (the adapter deletes users through Hanko's profile flow) and should require email verification. The "hanko" cookie must reach the app's host.

templ: version: v0.3.1070

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

type Config struct {
	// APIURL is the tenant's API URL, such as https://<tenant>.hanko.io. A self-hosted
	// Hanko may have a base path.
	APIURL string
	// SignedInPath is where the login page sends users who arrive without a next
	// path. Zero means "/".
	SignedInPath string
}

Config configures the adapter.

type Hanko

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

Hanko implements identity.Provider for Hanko.

func New

func New(cfg Config) (*Hanko, error)

New validates cfg and returns the adapter. It does not contact Hanko.

func (*Hanko) Authenticate

func (h *Hanko) Authenticate(r *http.Request) (identity.Identity, error)

Authenticate validates the session cookie with Hanko. Validation always asks Hanko, so a signed-out or deleted user's token stops working immediately.

func (*Hanko) Delete

func (h *Hanko) Delete(ctx context.Context, r *http.Request) error

Delete deletes the signed-in user through Hanko's profile flow. It returns nil only when Hanko reports the account_deleted state.

func (*Hanko) Logout

func (h *Hanko) Logout(w http.ResponseWriter, r *http.Request) error

Logout clears the session cookie, then ends the session at Hanko. The cookie is cleared even when Hanko cannot be reached; the error reports that case.

func (*Hanko) Mount

func (h *Hanko) Mount(r gin.IRouter, layout ui.Layout)

Mount adds the sign-in page at "login" under r, rendered inside layout. A user who is already signed in continues to the next path.

func (*Hanko) MountProfile

func (h *Hanko) MountProfile(r gin.IRouter, layout ui.Layout, logoutPath, emailChangedPath string, emailChanged func(c *gin.Context, email string) error)

MountProfile adds the profile UI's routes under r, the settings page's group, which must require sign-in. logoutPath is the sign-out route, emailChangedPath the page shown after an email change signs the user out, and emailChanged records a confirmed new address.

func (*Hanko) Name

func (h *Hanko) Name() string

Name returns "hanko".

func (*Hanko) ProfileCSP

func (h *Hanko) ProfileCSP() web.CSP

ProfileCSP lists what pages that show the profile UI must allow.

func (*Hanko) ProfileSection

func (h *Hanko) ProfileSection(c *gin.Context) templ.Component

ProfileSection renders the profile UI for the signed-in user.

Jump to

Keyboard shortcuts

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