ident

package module
v0.0.0-...-62444c3 Latest Latest
Warning

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

Go to latest
Published: Dec 7, 2022 License: MIT Imports: 23 Imported by: 0

Documentation

Index

Constants

View Source
const AudChangeEmail = "_change_email"
View Source
const Audience = "aud"
View Source
const ExpiresAt = "exp"
View Source
const IdentAudience = "_ident"
View Source
const IssuedAt = "iat"
View Source
const Issuer = "iss"
View Source
const RegistrationAud = "_complete_registration"
View Source
const ResetPasswordAud = "_reset_password"
View Source
const Subject = "sub"

Variables

View Source
var ErrInvalidCredentials = e("invalid_credentials")
View Source
var ErrNoUser = openid.ErrNoUser
View Source
var _, _, Module = module.New("ident", messages)

Functions

func MarshalJSONOptionStruct

func MarshalJSONOptionStruct(s interface{}) ([]byte, error)

Types

type ChangeEmailRequest

type ChangeEmailRequest struct {
	ChangeEmailToken string `json:"changeEmailToken"`
}

type CompleteRegistrationRequest

type CompleteRegistrationRequest struct {
	RegistrationToken string `json:"registrationToken"`
	RedirectUri       string `json:"redirectUri"`
}

type DeleteUserResponse

type DeleteUserResponse struct {
	NumDeleted int `json:"numDeleted"`
}

type DeleteUsersRequest

type DeleteUsersRequest = Selection

type Email

type Email struct {
	*openid.Userinfo
	RedirectUri string
}

type ExchangeSocialLoginRequest

type ExchangeSocialLoginRequest struct {
	Auth        openid.AuthResponse `json:"auth"`
	Scope       string              `json:"scope"`
	Nonce       string              `json:"nonce"`
	RedirectUri string              `json:"redirectUri"`
}

type ExchangeSocialLoginResponse

type ExchangeSocialLoginResponse = openid.TokenResponse

type GetUsersRequest

type GetUsersRequest struct {
	Selection
	PageToken string `json:"pageToken"`
	PageSize  int    `json:"pageSize"`
}

type GetUsersResponse

type GetUsersResponse struct {
	Users         []*User `json:"users"`
	NumFound      int     `json:"numFound"`
	NumTotal      int     `json:"numTotal"`
	NextPageToken string  `json:"nextPageToken,omitempty"`
}

type IdTokenClaims

type IdTokenClaims struct {
	openid.Userinfo
	Nonce string
}

func (IdTokenClaims) Valid

func (claims IdTokenClaims) Valid() error

type InsertUsersRequest

type InsertUsersRequest struct {
	Users        []*NewUser `json:"users"`
	Issuer       string     `json:"iss"`
	IgnoreEmails bool       `json:"ignoreEmails"`
}

type InsertUsersResponse

type InsertUsersResponse struct {
	Ids []string `json:"ids"`
}

type InstructEmailChangeRequest

type InstructEmailChangeRequest struct {
	Email string `json:"email"`
}

type InstructPasswordResetRequest

type InstructPasswordResetRequest struct {
	Email       string `json:"email"`
	RedirectUri string `json:"redirectUri"`
}

type LoginRequest

type LoginRequest struct {
	Username string `json:"username"`
	Password string `json:"password"`

	Nonce string `json:"nonce,omitempty"`
}

type LoginResponse

type LoginResponse = openid.TokenResponse

type LogoutRequest

type LogoutRequest struct {
	RefreshToken string `json:"refreshToken"`
}

type NewUser

type NewUser struct {
	Userinfo

	Suspended bool `json:"suspended,omitempty"`

	Password Option[string] `json:"password,omitempty"`
}

type Option

type Option[T any] struct {
	// Value is the value of the option.
	Value T
	// Valid is true if the value is set.
	Valid bool
}

func NewOption

func NewOption[T any](value T) Option[T]

NewOption returns a new valid Option with the given value.

func (Option[T]) Get

func (o Option[T]) Get() interface{}

func (Option[T]) MarshalJSON

func (o Option[T]) MarshalJSON() ([]byte, error)

func (*Option[T]) Set

func (o *Option[T]) Set(i interface{})

func (Option[T]) String

func (o Option[T]) String() string

func (*Option[T]) UnmarshalJSON

func (o *Option[T]) UnmarshalJSON(data []byte) error

type RegistrationRequest

type RegistrationRequest struct {
	Userinfo
	Password    string `json:"password"`
	RedirectUri string `json:"redirectUri"`
}

type ResetPasswordRequest

type ResetPasswordRequest struct {
	ResetPasswordToken string `json:"resetPasswordToken"`
	Password           string `json:"password"`
	RedirectUri        string `json:"redirectUri"`
}

type Scopes

type Scopes = openid.Scopes

func NewScopes

func NewScopes(str string) Scopes

type Selection

type Selection struct {
	All    bool     `json:"all,omitempty"`
	Ids    []string `json:"ids,omitempty"`
	Email  string   `json:"email,omitempty"`
	Search string   `json:"search,omitempty"`
}

func (Selection) Empty

func (sel Selection) Empty() bool

type Server

type Server struct {
	*openid.Server

	Api map[string]http.Handler

	ScopeAdmin string

	SessionStore SessionStore
	UserStore    UserStore

	EmailHost                 string
	EmailHostPort             int
	EmailFrom                 string
	EmailFromDisplayName      string
	EmailEnableTLS            bool
	EmailEnaleStartTLS        bool
	EmailEnableAuthentication bool
	EmailUsername             string
	EmailPassword             string

	CompleteRegistrationTemplate *template.Template
	CompleteRegistrationSubject  string

	ChangeEmailTemplate *template.Template
	ChangeEmailSubject  string

	PasswordResetTemplate    *template.Template
	PasswordResetSubject     string
	PasswordResetDelay       time.Duration
	PasswordResetTokenExpiry time.Duration

	SendMail func(addr string, a smtp.Auth, from string, to []string, msg []byte) error
	// contains filtered or unexported fields
}

func NewServer

func NewServer(addr string, sessionStore SessionStore, userStore UserStore, socials []*SocialProvider, next http.Handler) *Server

func (*Server) CompleteRegistration

func (server *Server) CompleteRegistration(ctx context.Context, sub string, email string) (err error)

func (*Server) InstructEmailChange

func (server *Server) InstructEmailChange(ctx context.Context, sub string, email string) (err error)

func (*Server) Login

func (server *Server) Login(ctx context.Context, aud string, username string, password string, nonce string) (refreshToken string, accessToken string, grantedScopes []string, expiresIn int64, idToken string, err error)

func (*Server) ServeHTTP

func (server *Server) ServeHTTP(resp http.ResponseWriter, req *http.Request)

func (*Server) SocialLogin

func (server *Server) SocialLogin(iss string, redirectUri string) (redirectUri2 string, err error)

type SessionSelection

type SessionSelection struct {
	Id  string `json:"id"`  // session id
	Sub string `json:"sub"` // user id
}

type SessionStore

type SessionStore interface {
	openid.SessionStore
	UpdateSessions(ctx context.Context, sess string, sub string, addScopes []string, removeScopes []string) (numUpdated int, err error)
}

type Social

type Social struct {
	Iss     string `json:"iss"`
	Profile string `json:"profile,omitempty"`
	Website string `json:"website,omitempty"`
	Picture string `json:"picture,omitempty"`
}

type SocialLoginRequest

type SocialLoginRequest struct {
	Iss         string `json:"iss"`
	RedirectUri string `json:"redirectUri"`
}

type SocialLoginResponse

type SocialLoginResponse struct {
	RedirectUri string `json:"redirectUri"`
}

type SocialProvider

type SocialProvider struct {
	Scope        string
	ClientId     string
	ClientSecret string
	Config       *openid.Configuration
}

func (SocialProvider) Exchange

func (p SocialProvider) Exchange(ctx context.Context, server *Server, code string) (*openid.TokenResponse, error)

func (SocialProvider) OAuth2Config

func (p SocialProvider) OAuth2Config(server *Server) *oauth2.Config

func (SocialProvider) Token

func (p SocialProvider) Token(ctx context.Context, server *Server, a *openid.AuthResponse) (t *openid.TokenResponse, err error)

func (SocialProvider) Userinfo

func (p SocialProvider) Userinfo(ctx context.Context, server *Server, t *openid.TokenResponse) (info *openid.Userinfo, err error)

type Store

type Store interface {
	UserStore
	SessionStore
}

type UpdateSessionRequest

type UpdateSessionRequest struct {
	SessionSelection

	AddScopes    []string `json:"addScopes"`
	RemoveScopes []string `json:"removeScopes"`
}

type UpdateSessionResponse

type UpdateSessionResponse struct {
	NumUpdated int `json:"numUpdated"`
}

type UpdateUserResponse

type UpdateUserResponse struct {
	NumUpdated int `json:"numUpdated"`
}

type UpdateUsersRequest

type UpdateUsersRequest struct {
	Selection  Selection  `json:"sel"`
	UserUpdate UserUpdate `json:"update"`
}

type User

type User struct {
	Userinfo

	Suspended bool `json:"suspended,omitempty"`

	Socials []Social `json:"socials,omitempty"`
}

type UserStore

type UserStore interface {
	openid.UserStore

	LoginUser(ctx context.Context, username string, password string) (sub string, err error)

	RegisterUsers(ctx context.Context, iss string, ignoreEmails bool, users []*NewUser) (ids []string, err error)

	UpdateUsers(ctx context.Context, sel Selection, u *UserUpdate) (numUpdated int, err error)

	DeleteUsers(ctx context.Context, sel Selection) (numDeleted int, err error)

	FindUsers(ctx context.Context, sel Selection, pageToken string, pageSize int) (users []*User, nextPageToken string, err error)

	CountUsers(ctx context.Context, sel Selection) (numSel int, numTotal int, err error)
}

type UserUpdate

type UserUpdate struct {
	Name       Option[string] `json:"name,omitempty"`
	GivenName  Option[string] `json:"given_name,omitempty"`
	FamilyName Option[string] `json:"family_name,omitempty"`
	MiddleName Option[string] `json:"middle_name,omitempty"`
	Nickname   Option[string] `json:"nickname,omitempty"`

	PreferredUsername Option[string] `json:"preferred_username,omitempty"`
	// requires priviliged scope
	PreferredUsernameVerified Option[bool] `json:"preferred_username_verified,omitempty"`

	Email Option[string] `json:"email,omitempty"`
	// requires priviliged scope
	EmailVerified Option[bool] `json:"email_verified,omitempty"`

	Gender      Option[string] `json:"gender,omitempty"`
	Birthdate   Option[string] `json:"birthdat,omitempty"`
	Zoneinfo    Option[string] `json:"zoneinfo,omitempty"`
	Locale      Option[string] `json:"locale,omitempty"`
	PhoneNumber Option[string] `json:"phone_number,omitempty"`
	// requires priviliged scope
	PhoneNumberVerified Option[bool]    `json:"phone_number_verified,omitempty"`
	Address             *openid.Address `json:"address,omitempty"`

	// requires priviliged scope
	Suspended Option[bool] `json:"suspended,omitempty"`

	NewPassword Option[string] `json:"new_password,omitempty"`
	// omitting this field requires priviliged scope
	OldPassword Option[string] `json:"old_password,omitempty"`
}

func (UserUpdate) MarshalJSON

func (u UserUpdate) MarshalJSON() ([]byte, error)

type Userinfo

type Userinfo = openid.Userinfo

Directories

Path Synopsis
examples

Jump to

Keyboard shortcuts

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