principal

package
v0.0.0-...-eb33cdb Latest Latest
Warning

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

Go to latest
Published: Feb 27, 2023 License: Apache-2.0 Imports: 1 Imported by: 2

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ContextWithUser

func ContextWithUser(ctx context.Context, u *User) context.Context

ContextWithUser store user information into context and return wrapped context.

Types

type Role

type Role struct {
	Name string
}

Role hold information asociated role name.

type Roles

type Roles map[string]Role

Roles represented as map to make it easier to lookup a role.

func (Roles) Add

func (r Roles) Add(role Role)

Add Role to Roles using Role.Name as key. Add will replace any role with the same name.

func (Roles) Get

func (r Roles) Get(name string) (Role, bool)

Get lookup role with given name, return Role and true if found, return empty Role and false otherwise.

func (Roles) Values

func (r Roles) Values() []Role

Values return slice of Role

type User

type User struct {
	Id       string `json:"id"`
	Username string `json:"preferred_username"`

	Email         string `json:"email,omitempty"`
	EmailVerified string `json:"email_verified,omitempty"`
	Name          string `json:"name,omitempty"`
	// contains filtered or unexported fields
}

User represent current user information, usually information contained in OIDC ID Token, see https://auth0.com/docs/secure/tokens/id-tokens/id-token-structure for available claims. However, since we are using keycloak as our default IdP we should adapt to keycloak about which fields are optional. As of this writing, only Id (sub) and username (preferred_username) is mandatory in keycloak.

func UserFromContext

func UserFromContext(ctx context.Context) (*User, bool)

UserFromContext return stored user in the context, return user, true if found or return nil, false otherwise.

func (*User) Roles

func (u *User) Roles() Roles

Roles return list of roles (as map) asociated with user, if roles nil then return empty map.

Jump to

Keyboard shortcuts

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