identity

package
v0.0.1-0...-6deec57 Latest Latest
Warning

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

Go to latest
Published: Jun 4, 2022 License: MIT Imports: 2 Imported by: 0

README

identity GoDoc

Package identity provides type that allows to authorize request

Download:

go get -u github.com/bradishungry/go-api-learning/pkg/identity

Package identity provides type that allows to authorize request

Documentation

Overview

Package identity provides type that allows to authorize request

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ContextWithIdentity

func ContextWithIdentity(ctx context.Context, i *Identity) context.Context

ContextWithIdentity returns a new Context that carries value i.

Types

type Identity

type Identity struct {
	Token        string     `json:"token"`
	Permission   Permission `json:"permission"`
	UserID       uuid.UUID  `json:"user_id"`
	ClientID     uuid.UUID  `json:"client_id,omitempty"`
	ClientDomain string     `json:"client_domain,omitempty"`
}

Identity data to be encode in auth token

func FromContext

func FromContext(ctx context.Context) (*Identity, bool)

FromContext returns the Identity value stored in ctx, if any.

type Permission

type Permission uint8

Flag type

const (
	PermissionUserRead Permission = 1 << iota
	PermissionUserWrite
	PermissionClientWrite
	PermissionClientRead
	PermissionTokenRead
)

Execution context flags

func (Permission) Add

func (p Permission) Add(flag Permission) Permission

Add permission

func (Permission) Has

func (p Permission) Has(flag Permission) bool

Has permission

func (Permission) Remove

func (p Permission) Remove(flag Permission) Permission

Remove permission

Jump to

Keyboard shortcuts

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