Error response enhancements, CoreID auth client backend
This commit is contained in:
@@ -1,10 +1,11 @@
|
||||
import {Inject, Injectable} from '../../di'
|
||||
import {Awaitable, Maybe} from '../../util'
|
||||
import {Awaitable, HTTPStatus, Maybe} from '../../util'
|
||||
import {Authenticatable, AuthenticatableRepository} from '../types'
|
||||
import {Logging} from '../../service/Logging'
|
||||
import {UserAuthenticatedEvent} from '../event/UserAuthenticatedEvent'
|
||||
import {UserFlushedEvent} from '../event/UserFlushedEvent'
|
||||
import {Bus} from '../../support/bus'
|
||||
import {HTTPError} from '../../http/HTTPError'
|
||||
|
||||
/**
|
||||
* Base-class for a context that authenticates users and manages security.
|
||||
@@ -95,6 +96,20 @@ export abstract class SecurityContext {
|
||||
return this.authenticatedUser
|
||||
}
|
||||
|
||||
/** Get the current user or throw an authorization error. */
|
||||
user(): Authenticatable {
|
||||
if ( !this.hasUser() ) {
|
||||
throw new HTTPError(HTTPStatus.UNAUTHORIZED)
|
||||
}
|
||||
|
||||
const user = this.getUser()
|
||||
if ( !user ) {
|
||||
throw new HTTPError(HTTPStatus.UNAUTHORIZED)
|
||||
}
|
||||
|
||||
return user
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if there is a currently authenticated user.
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user