idputil

package
v1.10.2 Latest Latest
Warning

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

Go to latest
Published: Jul 26, 2021 License: AGPL-3.0 Imports: 12 Imported by: 8

Documentation

Overview

Package idputil contains utility routines common to many identity providers.

Index

Constants

View Source
const LoginCookieName = "candid-login"

LoginCookieName is the name of the cookie used to store LoginState whilst a login is being processed.

View Source
const LoginCookiePath = "/login"

LoginCookiePath is the path to associate with the cookie storing the current login state.

Variables

View Source
var ReservedUsernames = map[string]bool{
	"admin":    true,
	"everyone": true,
}

Functions

func BadRequestf

func BadRequestf(w http.ResponseWriter, f string, args ...interface{})

BadRequestf writes the given bad request message to the given ResponseWriter. It should be used by IDPs when they do not have enough state to pass the error message along to the initiating page.

func CookiePathRelativeToLocation added in v1.6.0

func CookiePathRelativeToLocation(cookiePath, location string, skipLocation bool) string

CookiePathRelativeToLocation returns the Login Cookie Path relative to the sub-path in the location URL given. If skipLocation = true, then it's a no-op.

func DischargeID

func DischargeID(req *http.Request) string

DischargeID gets the discharge ID from the given request using the standard form value.

func GetLoginMethods

func GetLoginMethods(ctx context.Context, c *httprequest.Client, u *url.URL, v interface{}) error

GetLoginMethods uses c to perform a request to get the list of available login methods from u. The result is unmarshalled into v.

func HandleLoginForm

func HandleLoginForm(
	ctx context.Context,
	w http.ResponseWriter,
	req *http.Request,
	idpChoice params.IDPChoiceDetails,
	tmpl *template.Template,
	loginUser func(ctx context.Context, username, password string) (*store.Identity, error),
) (*store.Identity, error)

HandleLoginForm is a handler that displays and process a standard login form.

func NameWithDomain

func NameWithDomain(name, domain string) string

NameWithDomain builds a name out of name and domain. If domain is empty then name is returned unchanged.

func RedirectURL

func RedirectURL(prefix, path, state string) string

RedirectURL creates a URL addressed to the given path within the IDP handler and adds the given state.

func RegistrationForm

func RegistrationForm(ctx context.Context, w http.ResponseWriter, params RegistrationParams, t *template.Template) error

RegistrationForm writes a registration form to the given writer using the given parameters.

func RequestParams

func RequestParams(ctx context.Context, w http.ResponseWriter, req *http.Request) httprequest.Params

RequestParams creates an httprequest.Params object from the given fields.

func ServiceURL

func ServiceURL(location, dest string) string

ServiceURL determines the URL within the specified location. If the given dest is a relative URL then a new url is calculated relative to location, otherwise it is returned unchanged.

func State

func State(req *http.Request) string

State gets the state from the given request using the standard form value.

func URL

func URL(prefix, path, dischargeID string) string

URL creates a URL addressed to the given path within the IDP handler and adds the given dischargeID (when specified).

Types

type LoginFormParams

type LoginFormParams struct {
	params.IDPChoiceDetails

	// Action contains the action parameter for the form.
	Action string

	// Error contains an error message from the previous, failed,
	// login attempt.
	Error string
}

LoginFormParams contains the parameters sent to the login-form template.

type LoginState

type LoginState struct {
	// ReturnTo holds the address to return to after the login has
	// completed.
	ReturnTo string

	// State holds an opaque value from the original requesing server
	// that will be sent back to the ReturnTo URL when the login
	// attempt completes.
	State string

	// Expires holds the time that this login attempt should expire.
	Expires time.Time

	// ProvideID holds the ProviderID of an authenticated user. It is
	// only used when the user that has authenticaated requires
	// registration.
	ProviderID store.ProviderIdentity
}

LoginState holds the state of the current loging process.

type RegistrationParams

type RegistrationParams struct {
	// State contains some opaque state for the registration. It can
	// be used to pass arbitrary data back to the idp once the
	// registration is processed.
	State string

	// Username contains the preferred username for the user. This
	// will be used to populate the username input.
	Username string

	// Error contains an error message if the registration failed.
	Error string

	// Domain contains the domain in which the user is being created.
	// This cannot be modified by the user.
	Domain string

	// FullName contains the full name of the user. This is used to
	// populate the fullname input.
	FullName string

	// Email contains the email address of the user. This is used to
	// populate the email input.
	Email string
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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