Add api authorization logging
This commit is contained in:
@@ -6,14 +6,21 @@ class APIRouteMiddleware extends Middleware {
|
||||
}
|
||||
|
||||
async test(req, res, next, { allow_token = true, allow_user = true }) {
|
||||
if ( !req.additional_api_log_data ) req.additional_api_log_data = {}
|
||||
|
||||
// First, check if there is a user in the session.
|
||||
if ( allow_user && req.user ) {
|
||||
req.additional_api_log_data.authorized_by = 'user'
|
||||
return next()
|
||||
} else if ( allow_token ) {
|
||||
if ( !req.oauth ) req.oauth = {}
|
||||
req.additional_api_log_data.attempted_token_auth = true
|
||||
|
||||
return req.app.oauth2.authorise()(req, res, async e => {
|
||||
if ( e ) return next(e)
|
||||
|
||||
req.additional_api_log_data.authorized_by = 'token'
|
||||
|
||||
// Look up the OAuth2 client an inject it into the route
|
||||
if ( req.user && req.user.id ) {
|
||||
const User = this.models.get('auth:User')
|
||||
@@ -44,6 +51,9 @@ class APIRouteMiddleware extends Middleware {
|
||||
.message('This OAuth2 client is no longer authorized.')
|
||||
.api()
|
||||
|
||||
req.additional_api_log_data.token_client_id = client.uuid
|
||||
req.additional_api_log_data.token = bearer
|
||||
|
||||
req.oauth.token = token
|
||||
req.oauth.client = client
|
||||
} else
|
||||
|
||||
Reference in New Issue
Block a user