clory

package
v0.29.2 Latest Latest
Warning

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

Go to latest
Published: May 3, 2024 License: MIT Imports: 11 Imported by: 0

Documentation

Overview

Package clory provides ory-powered auth functionality.

Index

Constants

View Source
const AnonymousIdentityID = "00000000-0000-4000-8000-000000000002"

AnonymousIdentityID declares the special identity id for anonymous users.

View Source
const AnonymousSessionID = "00000000-0000-4000-8000-000000000001"

AnonymousSessionID declares the special session id for anonymous session.

Variables

View Source
var AnonymousSession = &orysdk.Session{
	Id:       AnonymousSessionID,
	Active:   orysdk.PtrBool(true),
	Identity: &orysdk.Identity{Id: AnonymousIdentityID},
}

AnonymousSession is returned from authentication calls when they fail but anonymous access is allowed.

View Source
var ErrUnauthenticated = errors.New("unauthenticated")

ErrUnauthenticated defines an error for failing to authenticate.

Functions

func NewClientAPIs

func NewClientAPIs(cfg Config) (FrontendAPI, PermissionAPI)

NewClientAPIs inits the raw Ory SDK API Client.

func Provide

func Provide() fx.Option

Provide configures the DI for providng rpc.

func Session

func Session(ctx context.Context) *orysdk.Session

Session returns the session stored in the context, or nil if it isn't.

func WithSession

func WithSession(ctx context.Context, sess *orysdk.Session) context.Context

WithSession adds the session to the middleware.

Types

type Config

type Config struct {
	// Ory endpoint.
	Endpoint *url.URL `env:"ENDPOINT" envDefault:"http://localhost:4000"`
}

Config configures this package.

type FrontendAPI

type FrontendAPI interface {
	ToSession(ctx context.Context) orysdk.FrontendAPIToSessionRequest
	ToSessionExecute(r orysdk.FrontendAPIToSessionRequest) (*orysdk.Session, *http.Response, error)
}

FrontendAPI describe the external interface.

type Ory

type Ory struct {
	// contains filtered or unexported fields
}

Ory auth module.

func New

func New(cfg Config, logs *zap.Logger, front FrontendAPI, perm PermissionAPI) *Ory

New inits the ory auth module.

func (Ory) Authenticate added in v0.25.6

func (o Ory) Authenticate(ctx context.Context, cookie string, allowAnonymous bool) (*orysdk.Session, error)

Authenticate implements the core authentication logic. The function that actually interacts with Ory is passed in for easier testing.

func (Ory) BrowserLoginURL

func (o Ory) BrowserLoginURL() *url.URL

BrowserLoginURL returns the url for starting the login flow.

func (Ory) Private

func (o Ory) Private(next http.Handler) http.Handler

Private middleware will try to fetch a Ory session for the request or else return a 401 Unauthorized response.

type PermissionAPI added in v0.25.6

type PermissionAPI interface {
	CheckPermission(ctx context.Context) orysdk.PermissionAPICheckPermissionRequest
	CheckPermissionExecute(r orysdk.PermissionAPICheckPermissionRequest) (
		*orysdk.CheckPermissionResult, *http.Response, error)
}

PermissionAPI describe the external interface.

Jump to

Keyboard shortcuts

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