Documentation ¶
Index ¶
- Constants
- Variables
- func CreateAdminClient(ctx context.Context, db Database) (*model.ClientInfo, error)
- type AuthorizationDB
- type BadgerDB
- func (db *BadgerDB) Close() error
- func (db *BadgerDB) CreateSession(ctx context.Context, request *model.AuthorizationRequest) error
- func (db *BadgerDB) DeleteClient(ctx context.Context, clientID string) error
- func (db *BadgerDB) DeleteScope(ctx context.Context, scope string) error
- func (db *BadgerDB) DropAll(ctx context.Context) error
- func (db *BadgerDB) GetClient(ctx context.Context, clientID string) (client *model.ClientInfo, err error)
- func (db *BadgerDB) GetDefaultAdminClient(ctx context.Context) (*model.ClientInfo, error)
- func (db *BadgerDB) GetRequestInfo(ctx context.Context, requestID string) (*model.AuthorizationRequest, error)
- func (db *BadgerDB) GetScope(ctx context.Context, scopeName string) (s *model.Scope, err error)
- func (db *BadgerDB) GetTokenByID(ctx context.Context, tokenID string) (token string, err error)
- func (db *BadgerDB) GetUserByID(ctx context.Context, id string) (*model.User, error)
- func (db *BadgerDB) GetUserByUsername(ctx context.Context, username, clientID string) (user *model.User, err error)
- func (db *BadgerDB) IsTokenSeen(ctx context.Context, token *jwt.Token) (seen bool, err error)
- func (db *BadgerDB) ListClients(ctx context.Context, opts ...model.ClientOption) ([]*model.ClientInfo, error)
- func (db *BadgerDB) ListClientsByPredicate(ctx context.Context, predicate func(*model.ClientInfo) bool) ([]*model.ClientInfo, error)
- func (db *BadgerDB) ListScopes(ctx context.Context) ([]*model.Scope, error)
- func (db *BadgerDB) LookupSessionByCode(ctx context.Context, code string) (request *model.AuthorizationRequest, err error)
- func (db *BadgerDB) RegisterClient(ctx context.Context, clientInfo *model.ClientInfo, opt model.ClientOption) (*model.ClientInfo, error)
- func (db *BadgerDB) RegisterScope(ctx context.Context, scope string) (*model.Scope, error)
- func (db *BadgerDB) RegisterToken(ctx context.Context, token *jwt.Token) error
- func (db *BadgerDB) RegisterUser(ctx context.Context, user *model.User) error
- func (db *BadgerDB) UpdateClient(ctx context.Context, clientUpdate model.ClientInfoUpdate) (*model.ClientInfo, error)
- func (db *BadgerDB) UpdateRequestInfo(ctx context.Context, requestInfo *model.AuthorizationRequest) error
- func (db *BadgerDB) VerifyUsernameAndPassword(ctx context.Context, username, clientID, password string) (*model.User, error)
- type ClientDB
- type Database
- type DgraphDatabase
- func (db *DgraphDatabase) Close() error
- func (db *DgraphDatabase) CreateSession(ctx context.Context, request *model.AuthorizationRequest) error
- func (db *DgraphDatabase) DeleteClient(ctx context.Context, clientID string) error
- func (db *DgraphDatabase) DeleteScope(ctx context.Context, scope string) error
- func (db *DgraphDatabase) DropAll(ctx context.Context) error
- func (db *DgraphDatabase) GetClient(ctx context.Context, clientID string) (*model.ClientInfo, error)
- func (db *DgraphDatabase) GetDefaultAdminClient(ctx context.Context) (*model.ClientInfo, error)
- func (db *DgraphDatabase) GetRequestInfo(ctx context.Context, requestID string) (*model.AuthorizationRequest, error)
- func (db *DgraphDatabase) GetScope(ctx context.Context, scopeName string) (*model.Scope, error)
- func (db *DgraphDatabase) GetTokenByID(ctx context.Context, tokenID string) (string, error)
- func (db *DgraphDatabase) GetUserByID(ctx context.Context, id string) (*model.User, error)
- func (db *DgraphDatabase) GetUserByUsername(ctx context.Context, username, clientID string) (*model.User, error)
- func (db *DgraphDatabase) IsTokenSeen(ctx context.Context, token *jwt.Token) (bool, error)
- func (db *DgraphDatabase) ListClients(ctx context.Context, opt ...model.ClientOption) ([]*model.ClientInfo, error)
- func (db *DgraphDatabase) ListScopes(ctx context.Context) ([]*model.Scope, error)
- func (db *DgraphDatabase) LookupSessionByCode(ctx context.Context, code string) (*model.AuthorizationRequest, error)
- func (db *DgraphDatabase) RegisterClient(ctx context.Context, clientInfo *model.ClientInfo, opt model.ClientOption) (*model.ClientInfo, error)
- func (db *DgraphDatabase) RegisterScope(ctx context.Context, scopeName string) (*model.Scope, error)
- func (db *DgraphDatabase) RegisterToken(ctx context.Context, token *jwt.Token) error
- func (db *DgraphDatabase) RegisterUser(ctx context.Context, user *model.User) error
- func (db *DgraphDatabase) Seed(ctx context.Context) (*model.ClientInfo, error)
- func (db *DgraphDatabase) UpdateClient(ctx context.Context, clientUpdate model.ClientInfoUpdate) (*model.ClientInfo, error)
- func (db *DgraphDatabase) UpdateRequestInfo(ctx context.Context, requestInfo *model.AuthorizationRequest) error
- func (db *DgraphDatabase) VerifyUsernameAndPassword(ctx context.Context, username, clientID, password string) (*model.User, error)
- type DgraphOptions
- type DiscoveryDB
- type ScopeDB
- type UserDB
Constants ¶
const DefaultTimeout = time.Second * 3
DefaultTimeout is the default length of time to wait for a database operation to complete.
Variables ¶
var (
ErrNotFound = errors.New("Key not found")
)
Common errors
Functions ¶
func CreateAdminClient ¶
CreateAdminClient creates an admin client in the database.
Types ¶
type AuthorizationDB ¶
type AuthorizationDB interface { CreateSession(ctx context.Context, request *model.AuthorizationRequest) error GetRequestInfo(ctx context.Context, requestID string) (*model.AuthorizationRequest, error) UpdateRequestInfo(ctx context.Context, requestInfo *model.AuthorizationRequest) error LookupSessionByCode(ctx context.Context, code string) (*model.AuthorizationRequest, error) RegisterToken(ctx context.Context, token *jwt.Token) error IsTokenSeen(ctx context.Context, token *jwt.Token) (bool, error) GetTokenByID(ctx context.Context, tokenID string) (string, error) }
AuthorizationDB handles interactions with the authorization database, which may be the same as other databases or not.
type BadgerDB ¶
BadgerDB holds a connection to a Badger backend.
func NewBadgerDB ¶
func NewBadgerDB(inMemory bool, opts *config.DatabaseConfig) (*BadgerDB, error)
NewBadgerDB creates a new database with a Badger backend. Pass `true` to create an in-memory database (useful in tests, for example).
func (*BadgerDB) CreateSession ¶
CreateSession creates a session for the given client which includes the authorization code and code verifier information (PKCE), so that it can be verified later.
func (*BadgerDB) DeleteClient ¶
DeleteClient deletes the client from the database.
func (*BadgerDB) DeleteScope ¶
DeleteScope removes a scope from the database.
func (*BadgerDB) GetClient ¶
func (db *BadgerDB) GetClient(ctx context.Context, clientID string) (client *model.ClientInfo, err error)
GetClient returns client information for the given client ID.
func (*BadgerDB) GetDefaultAdminClient ¶
GetDefaultAdminClient returns the default admin client for the database.
func (*BadgerDB) GetRequestInfo ¶
func (db *BadgerDB) GetRequestInfo(ctx context.Context, requestID string) (*model.AuthorizationRequest, error)
GetRequestInfo returns the session info associated with this ID.
func (*BadgerDB) GetTokenByID ¶
GetTokenByID looks up and returns the encoded token corresponding to the provided ID.
func (*BadgerDB) GetUserByID ¶
GetUserByID retrieves user's info based off an ID.
func (*BadgerDB) GetUserByUsername ¶
func (db *BadgerDB) GetUserByUsername(ctx context.Context, username, clientID string) (user *model.User, err error)
GetUserByUsername retrieves user's info based off a username.
func (*BadgerDB) IsTokenSeen ¶
IsTokenSeen returns an error if the token has been seen before. If not, it first records the token information so that subsequent calls return true.
func (*BadgerDB) ListClients ¶
func (db *BadgerDB) ListClients(ctx context.Context, opts ...model.ClientOption) ([]*model.ClientInfo, error)
ListClients lists all clients in the database.
func (*BadgerDB) ListClientsByPredicate ¶
func (db *BadgerDB) ListClientsByPredicate(ctx context.Context, predicate func(*model.ClientInfo) bool) ([]*model.ClientInfo, error)
ListClientsByPredicate lists all clients in the database based off a predicate.
func (*BadgerDB) ListScopes ¶
ListScopes returns all scopes in the database.
func (*BadgerDB) LookupSessionByCode ¶
func (db *BadgerDB) LookupSessionByCode(ctx context.Context, code string) (request *model.AuthorizationRequest, err error)
LookupSessionByCode retrieves a request session's data based off the authorization code.
func (*BadgerDB) RegisterClient ¶
func (db *BadgerDB) RegisterClient(ctx context.Context, clientInfo *model.ClientInfo, opt model.ClientOption) (*model.ClientInfo, error)
RegisterClient registers the client with the provided information.
func (*BadgerDB) RegisterScope ¶
RegisterScope adds a new scope to the database.
func (*BadgerDB) RegisterToken ¶
RegisterToken saves the given tokens to the database for later reference.
func (*BadgerDB) RegisterUser ¶
RegisterUser registers a new user in the authentication database.
func (*BadgerDB) UpdateClient ¶
func (db *BadgerDB) UpdateClient(ctx context.Context, clientUpdate model.ClientInfoUpdate) (*model.ClientInfo, error)
UpdateClient updates the client with the provided information.
func (*BadgerDB) UpdateRequestInfo ¶
func (db *BadgerDB) UpdateRequestInfo(ctx context.Context, requestInfo *model.AuthorizationRequest) error
UpdateRequestInfo updates the information pertinent to this request.
type ClientDB ¶
type ClientDB interface { ListClients(ctx context.Context, opt ...model.ClientOption) ([]*model.ClientInfo, error) GetClient(ctx context.Context, clientID string) (*model.ClientInfo, error) UpdateClient(ctx context.Context, client model.ClientInfoUpdate) (*model.ClientInfo, error) RegisterClient(ctx context.Context, clientInfo *model.ClientInfo, opt model.ClientOption) (*model.ClientInfo, error) DeleteClient(ctx context.Context, clientID string) error }
ClientDB handles interactions with the client database.
type Database ¶
type Database interface { ClientDB AuthorizationDB UserDB DiscoveryDB ScopeDB GetDefaultAdminClient(ctx context.Context) (*model.ClientInfo, error) Close() error DropAll(ctx context.Context) error }
Database handles all interactions with the data backend.
type DgraphDatabase ¶
type DgraphDatabase struct {
// contains filtered or unexported fields
}
DgraphDatabase holds connection to a Dgraph DB instance.
func NewDgraphDatabase ¶
func NewDgraphDatabase(ctx context.Context, opts *config.DatabaseConfig) (*DgraphDatabase, error)
NewDgraphDatabase creates a new Dgraph database connection uses settings from the loaded configuration.
func (*DgraphDatabase) Close ¶
func (db *DgraphDatabase) Close() error
Close handles closing all connections to the database.
func (*DgraphDatabase) CreateSession ¶
func (db *DgraphDatabase) CreateSession(ctx context.Context, request *model.AuthorizationRequest) error
CreateSession creates a session for the given client which includes the authorization code and code verifier information (PKCE), so that it can be verified later.
func (*DgraphDatabase) DeleteClient ¶
func (db *DgraphDatabase) DeleteClient(ctx context.Context, clientID string) error
DeleteClient deletes the client from the database.
func (*DgraphDatabase) DeleteScope ¶
func (db *DgraphDatabase) DeleteScope(ctx context.Context, scope string) error
DeleteScope removes a scope from the database.
func (*DgraphDatabase) DropAll ¶
func (db *DgraphDatabase) DropAll(ctx context.Context) error
clear drops all data from the database.
func (*DgraphDatabase) GetClient ¶
func (db *DgraphDatabase) GetClient(ctx context.Context, clientID string) (*model.ClientInfo, error)
GetClient returns client information for the given client ID.
func (*DgraphDatabase) GetDefaultAdminClient ¶
func (db *DgraphDatabase) GetDefaultAdminClient(ctx context.Context) (*model.ClientInfo, error)
GetDefaultAdminClient returns the current admin client. It does not create one if it does not exist already.
func (*DgraphDatabase) GetRequestInfo ¶
func (db *DgraphDatabase) GetRequestInfo(ctx context.Context, requestID string) (*model.AuthorizationRequest, error)
GetRequestInfo returns the session info associated with this ID.
func (*DgraphDatabase) GetTokenByID ¶
GetTokenByID looks up and returns the encoded token corresponding to the provided ID.
func (*DgraphDatabase) GetUserByID ¶
GetUserByID retrieves user's info based off a user's ID.
func (*DgraphDatabase) GetUserByUsername ¶
func (db *DgraphDatabase) GetUserByUsername(ctx context.Context, username, clientID string) (*model.User, error)
GetUserByUsername retrieves user's info based off a username.
func (*DgraphDatabase) IsTokenSeen ¶
IsTokenSeen returns an error if the token has been seen before. If not, it first records the token information so that subsequent calls return true.
func (*DgraphDatabase) ListClients ¶
func (db *DgraphDatabase) ListClients(ctx context.Context, opt ...model.ClientOption) ([]*model.ClientInfo, error)
ListClients lists all clients in the database.
func (*DgraphDatabase) ListScopes ¶
ListScopes returns all scopes in the database.
func (*DgraphDatabase) LookupSessionByCode ¶
func (db *DgraphDatabase) LookupSessionByCode(ctx context.Context, code string) (*model.AuthorizationRequest, error)
LookupSessionByCode retrieves a request session's data based off the authorization code.
func (*DgraphDatabase) RegisterClient ¶
func (db *DgraphDatabase) RegisterClient(ctx context.Context, clientInfo *model.ClientInfo, opt model.ClientOption) (*model.ClientInfo, error)
RegisterClient registers the client with the provided information.
func (*DgraphDatabase) RegisterScope ¶
func (db *DgraphDatabase) RegisterScope(ctx context.Context, scopeName string) (*model.Scope, error)
RegisterScope adds a new scope to the database.
func (*DgraphDatabase) RegisterToken ¶
RegisterToken saves the given tokens to the database for later reference.
func (*DgraphDatabase) RegisterUser ¶
RegisterUser registers a new user in the authentication database.
func (*DgraphDatabase) Seed ¶
func (db *DgraphDatabase) Seed(ctx context.Context) (*model.ClientInfo, error)
Seed initializes the database schema and creates all defaults.
func (*DgraphDatabase) UpdateClient ¶
func (db *DgraphDatabase) UpdateClient(ctx context.Context, clientUpdate model.ClientInfoUpdate) (*model.ClientInfo, error)
UpdateClient updates the client with the provided information.
func (*DgraphDatabase) UpdateRequestInfo ¶
func (db *DgraphDatabase) UpdateRequestInfo(ctx context.Context, requestInfo *model.AuthorizationRequest) error
UpdateRequestInfo updates the information pertinent to this request.
func (*DgraphDatabase) VerifyUsernameAndPassword ¶
func (db *DgraphDatabase) VerifyUsernameAndPassword(ctx context.Context, username, clientID, password string) (*model.User, error)
VerifyUsernameAndPassword returns an error if the username and password combo do not match what's in the DB.
type DgraphOptions ¶
type DgraphOptions struct { GraphQLEndpoint string GrpcEndpoint string APIKey string Username string Password string SeedDB bool DropAll bool // Whether to drop all data }
DgraphOptions holds configuration options for the Dgraph database.
type DiscoveryDB ¶
type DiscoveryDB interface{}
DiscoveryDB handles interactions with the discovery database, which contains metadata about this program. It should be the same as AuthorizationDB.
type ScopeDB ¶
type ScopeDB interface { ListScopes(ctx context.Context) ([]*model.Scope, error) GetScope(ctx context.Context, scope string) (*model.Scope, error) RegisterScope(ctx context.Context, scope string) (*model.Scope, error) DeleteScope(ctx context.Context, scope string) error }
ScopeDB handles interactions with the scope database.
type UserDB ¶
type UserDB interface { RegisterUser(ctx context.Context, user *model.User) error GetUserByID(ctx context.Context, id string) (*model.User, error) GetUserByUsername(ctx context.Context, username, clientID string) (*model.User, error) VerifyUsernameAndPassword(ctx context.Context, username, clientID, password string) (*model.User, error) }
UserDB handles interactions with the authentication databse, which may or may not be the same as other databases.