devlogin

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Nov 27, 2026 License: Apache-2.0, MIT Imports: 14 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package devlogin signs people in for trying a server on one's own computer, and checks no one's identity: a page that lists the people of the organization, where the one chosen is who sends each request from then on (SignIn), and the header X-Person, for trying the API with a client such as curl (Header). It also has the checks that keep the two away from a server that serves people: they answer only a request sent on the computer the server runs on (Local), a server takes them only when it listens on a loopback address (OnLoopback), and not where the environment has the settings of signing in through the provider (NotWithProvider). Package serve uses them for -dev-login and for the header it takes when no other way of signing in is chosen.

Index

Constants

View Source
const (
	Cookie      = "ringi-dev-person"
	RolesCookie = "ringi-dev-roles"
	LoginPath   = "/login"
	LogoutPath  = "/logout"
)

The cookies that name the person and their roles, and the paths of signing in and out.

Variables

View Source
var ProviderSettings = []string{"RINGI_OIDC_CLIENT_SECRET", "RINGI_SESSION_KEYS"}

ProviderSettings are the environment variables of signing in through the provider that a server's command line reads (package serve: -oidc-client-secret and -session-keys): a process that has one is set up to serve people.

Functions

func Local

func Local(r *http.Request) bool

Local reports whether a request was sent on the computer the server runs on: its Host is a loopback address, and it has none of the headers a proxy adds to what it forwards. A proxy in front of a server that listens on a loopback address would otherwise bring other computers' requests to a sign-in that checks no one, under a Host it may have set to the server's address. (A proxy that adds none of them is not seen: these sign-ins are never put behind one.)

func Loopback

func Loopback(host string) bool

Loopback reports whether a request's Host (a name or an address, with or without a port) is a loopback address: localhost, 127.0.0.0/8 or ::1.

func NotWithProvider

func NotWithProvider(getenv func(string) string, what string) error

NotWithProvider answers an error when the environment (getenv) has one of ProviderSettings: a way of signing in that checks no one (what names it, for the error) does not run in a process set up to sign people in through the provider, where a flag left out would otherwise let anyone be anyone.

func OnLoopback

func OnLoopback(addr, what string) error

OnLoopback answers an error unless addr, an address to listen on (host:port), is a loopback one. A server takes a way of signing in that checks no one (the header X-Person, -dev-login, an agents' token that is a person's ID) only on such an address: what checks no one must not be reachable from another computer. what names the way, for the error.

func Roles

func Roles(written string) (roles []string, ok bool)

Roles reads roles written separated by commas, as the header X-Roles and the page of signing in take them: each trimmed of spaces, an empty one left out, one written twice kept once. ok is false for more than 16 roles, or one longer than 64 bytes or with a character that is not visible ASCII.

Types

type Header struct{}

Header signs in by the header X-Person, which names who sends a request (X-Roles their roles, separated by commas, as Roles reads them; staff when it is not sent, and no one when it cannot be read), only on a Local request: for trying the API with a client such as curl. It checks no one, as SignIn does: a server uses it only when it listens on a loopback address (OnLoopback), and a request whose Host is another name (a page of another site that made a browser send it to this computer under its own name) or that a proxy forwarded has no person.

func (Header) Authenticate

func (Header) Authenticate(r *http.Request) (server.Person, error)

Authenticate answers the person the header names, on a Local request.

type SignIn

type SignIn struct {
	// Server is the server whose organization's people may be chosen.
	Server *server.Server
}

SignIn signs people in on the computer the server runs on, for trying a server in a browser: its page lists the people of the organization, and the one chosen is who sends each request from then on (a cookie names them), with the roles chosen under the list (another cookie: none when none is chosen), for trying what the gate lets each role do: a link for each role that the gate of the examples declares, as the gate of a project ritsu ringi init makes does, opens the page with the role written (?roles=). An organization of more people than a picker of the pages lists (web.PicksListed) is not listed: the page finds people by a part of a name or an ID, as such a picker does, with no script. It checks no one's identity, so it answers only requests sent to a loopback address (localhost, 127.0.0.1, ::1) that no proxy forwarded (Local); a server starts it only when it listens on one (OnLoopback), and not where the environment has the provider's settings (NotWithProvider), as package serve does with -dev-login. It is a server.Authenticator, and it gives the pages the hooks of a sign-in (web.Config's Require, LoginURL and SignOut).

func (*SignIn) Authenticate

func (d *SignIn) Authenticate(r *http.Request) (server.Person, error)

Authenticate answers the person the cookie names, while the organization in effect today has them, with the roles they signed in with (none when they gave none: the gate takes them as it takes one with no role): server.ErrNoPerson with no cookie, for someone the organization does not have, and for a request that is not Local.

func (*SignIn) LoginURL

func (d *SignIn) LoginURL(returnTo string) string

LoginURL answers the address of signing in that comes back to returnTo, a path of this server.

func (*SignIn) Mount

func (d *SignIn) Mount(mux interface {
	Handle(pattern string, handler http.Handler)
})

Mount adds the routes of signing in and out: GET and POST LoginPath, POST LogoutPath. Added to the handler of the pages (web.Handler.Handle), they are behind its guards: a form another site sends is refused.

func (*SignIn) Require

func (d *SignIn) Require(next http.Handler) http.Handler

Require sends a browser that opens a page with no one signed in to the page of signing in, and back; anything else goes on (the pages answer a request with no person themselves).

Jump to

Keyboard shortcuts

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