apikey

package
v0.32.0 Latest Latest
Warning

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

Go to latest
Published: Feb 9, 2024 License: Apache-2.0 Imports: 23 Imported by: 0

Documentation

Index

Constants

View Source
const Audience = "apikey-v1/graphql-v1"

Audience is the JWT audience for GraphQL API keys.

View Source
const Issuer = "goalert"

Issuer is the JWT issuer for GraphQL API keys.

Variables

This section is empty.

Functions

func ContextWithPolicy

func ContextWithPolicy(ctx context.Context, p *GQLPolicy) context.Context

ContextWithPolicy returns a new context with the given Policy attached.

func NewGraphQLClaims

func NewGraphQLClaims(id uuid.UUID, policyHash []byte, expires time.Time) jwt.Claims

NewGraphQLClaims returns a new Claims object for a GraphQL API key with the embedded policy hash.

Types

type APIKeyInfo

type APIKeyInfo struct {
	ID          uuid.UUID
	Name        string
	Description string
	ExpiresAt   time.Time
	LastUsed    *APIKeyUsage
	CreatedAt   time.Time
	UpdatedAt   time.Time
	CreatedBy   *uuid.UUID
	UpdatedBy   *uuid.UUID
	Query       string
	Role        permission.Role
}

type APIKeyUsage

type APIKeyUsage struct {
	UserAgent string
	IP        string
	Time      time.Time
}

type Claims

type Claims struct {
	jwt.RegisteredClaims
	PolicyHash []byte `json:"pol"`
}

Claims is the set of claims that are encoded into a JWT for a GraphQL API key.

type GQLPolicy

type GQLPolicy struct {
	Version int
	Query   string
	Role    permission.Role
}

GQLPolicy is a GraphQL API key policy.

func PolicyFromContext

func PolicyFromContext(ctx context.Context) *GQLPolicy

PolicyFromContext returns the Policy associated with the given context.

type Middleware

type Middleware struct{}

func (Middleware) ExtensionName

func (Middleware) ExtensionName() string

func (Middleware) MutateOperationParameters

func (Middleware) MutateOperationParameters(ctx context.Context, rc *graphql.RawParams) *gqlerror.Error

func (Middleware) Validate

func (Middleware) Validate(schema graphql.ExecutableSchema) error

type NewAdminGQLKeyOpts

type NewAdminGQLKeyOpts struct {
	Name    string
	Desc    string
	Expires time.Time
	Role    permission.Role
	Query   string
}

NewAdminGQLKeyOpts is used to create a new GraphQL API key.

type Store

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

Store is used to manage API keys.

func NewStore

func NewStore(ctx context.Context, db *sql.DB, key keyring.Keyring) (*Store, error)

NewStore will create a new Store.

func (*Store) AuthorizeGraphQL

func (s *Store) AuthorizeGraphQL(ctx context.Context, tok, ua, ip string) (context.Context, error)

func (*Store) CreateAdminGraphQLKey

func (s *Store) CreateAdminGraphQLKey(ctx context.Context, opt NewAdminGQLKeyOpts) (uuid.UUID, string, error)

CreateAdminGraphQLKey will create a new GraphQL API key returning the ID and token.

func (*Store) DeleteAdminGraphQLKey

func (s *Store) DeleteAdminGraphQLKey(ctx context.Context, id uuid.UUID) error

func (*Store) FindAllAdminGraphQLKeys

func (s *Store) FindAllAdminGraphQLKeys(ctx context.Context) ([]APIKeyInfo, error)

func (*Store) UpdateAdminGraphQLKey

func (s *Store) UpdateAdminGraphQLKey(ctx context.Context, id uuid.UUID, name, desc *string) error

type UpdateKey

type UpdateKey struct {
	ID          uuid.UUID
	Name        string
	Description string
}

Jump to

Keyboard shortcuts

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