Rework authentication system
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
This commit is contained in:
@@ -3,21 +3,22 @@ import {Awaitable, JSONState, Maybe, Rehydratable} from '../util'
|
||||
/** Value that can be used to uniquely identify a user. */
|
||||
export type AuthenticatableIdentifier = string | number
|
||||
|
||||
export interface AuthenticatableCredentials {
|
||||
identifier: string,
|
||||
credential: string,
|
||||
}
|
||||
|
||||
/**
|
||||
* Base class for entities that can be authenticated.
|
||||
*/
|
||||
export abstract class Authenticatable implements Rehydratable {
|
||||
|
||||
/** Get the unique identifier of the user. */
|
||||
/** Get the globally-unique identifier of the user. */
|
||||
abstract getUniqueIdentifier(): AuthenticatableIdentifier
|
||||
|
||||
/** Get the repository-unique identifier of the user. */
|
||||
abstract getIdentifier(): AuthenticatableIdentifier
|
||||
|
||||
/** Get the human-readable identifier of the user. */
|
||||
abstract getDisplayIdentifier(): string
|
||||
abstract getDisplay(): string
|
||||
|
||||
/** Attempt to validate a credential of the user. */
|
||||
abstract validateCredential(credential: string): Awaitable<boolean>
|
||||
|
||||
abstract dehydrate(): Promise<JSONState>
|
||||
|
||||
@@ -28,16 +29,15 @@ export abstract class Authenticatable implements Rehydratable {
|
||||
* Base class for a repository that stores and recalls users.
|
||||
*/
|
||||
export abstract class AuthenticatableRepository {
|
||||
|
||||
/** Look up the user by their unique identifier. */
|
||||
abstract getByIdentifier(id: AuthenticatableIdentifier): Awaitable<Maybe<Authenticatable>>
|
||||
|
||||
/**
|
||||
* Attempt to look up and verify a user by their credentials.
|
||||
* Returns the user if the credentials are valid.
|
||||
* @param credentials
|
||||
*/
|
||||
abstract getByCredentials(credentials: AuthenticatableCredentials): Awaitable<Maybe<Authenticatable>>
|
||||
/** Returns true if this repository supports registering users. */
|
||||
abstract supportsRegistration(): boolean
|
||||
|
||||
abstract createByCredentials(credentials: AuthenticatableCredentials): Awaitable<Authenticatable>
|
||||
/** Create a user in this repository from an external Authenticatable instance. */
|
||||
abstract createFromExternal(user: Authenticatable): Awaitable<Authenticatable>
|
||||
|
||||
/** Create a user in this repository from basic credentials. */
|
||||
abstract createFromCredentials(username: string, password: string): Awaitable<Authenticatable>
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user