1
1
import config from 'config' ;
2
- import debug from 'debug' ;
2
+ import debugLib from 'debug' ;
3
3
4
4
import errors from '../../lib/errors' ;
5
5
import { authenticateUser } from './authentication' ;
@@ -8,6 +8,8 @@ import models from '../../models';
8
8
9
9
const { Unauthorized } = errors ;
10
10
11
+ const debug = debugLib ( 'auth' ) ;
12
+
11
13
/**
12
14
* Check Client App
13
15
*
@@ -21,7 +23,7 @@ export async function checkClientApp(req, res, next) {
21
23
where : { type : 'apiKey' , apiKey } ,
22
24
} ) ;
23
25
if ( app ) {
24
- debug ( 'auth' ) ( ' Valid Client App (apiKey)') ;
26
+ debug ( 'Valid Client App (apiKey)' ) ;
25
27
req . clientApp = app ;
26
28
const collectiveId = app . CollectiveId ;
27
29
if ( collectiveId ) {
@@ -35,7 +37,7 @@ export async function checkClientApp(req, res, next) {
35
37
}
36
38
next ( ) ;
37
39
} else {
38
- debug ( 'auth' ) ( `Invalid Client App (apiKey: ${ apiKey } ).` ) ;
40
+ debug ( `Invalid Client App (apiKey: ${ apiKey } ).` ) ;
39
41
next ( new Unauthorized ( `Invalid Api Key: ${ apiKey } .` ) ) ;
40
42
}
41
43
} else if ( clientId ) {
@@ -44,16 +46,16 @@ export async function checkClientApp(req, res, next) {
44
46
where : { clientId } ,
45
47
} ) ;
46
48
if ( app ) {
47
- debug ( 'auth' ) ( ' Valid Client App') ;
49
+ debug ( 'Valid Client App' ) ;
48
50
req . clientApp = app ;
49
51
next ( ) ;
50
52
} else {
51
- debug ( 'auth' ) ( `Invalid Client App (clientId: ${ clientId } ).` ) ;
53
+ debug ( `Invalid Client App (clientId: ${ clientId } ).` ) ;
52
54
next ( new Unauthorized ( `Invalid Client Id: ${ clientId } .` ) ) ;
53
55
}
54
56
} else {
55
57
next ( ) ;
56
- debug ( 'auth' ) ( ' No Client App') ;
58
+ debug ( 'No Client App' ) ;
57
59
}
58
60
}
59
61
@@ -94,16 +96,16 @@ export function authorizeClientApp(req, res, next) {
94
96
95
97
const apiKey = req . get ( 'Api-Key' ) || req . query . apiKey || req . query . api_key || req . body . api_key ;
96
98
if ( req . clientApp ) {
97
- debug ( 'auth' ) ( ' Valid Client App') ;
99
+ debug ( 'Valid Client App' ) ;
98
100
next ( ) ;
99
101
} else if ( apiKey === config . keys . opencollective . apiKey ) {
100
- debug ( 'auth' ) ( `Valid API key: ${ apiKey } ` ) ;
102
+ debug ( `Valid API key: ${ apiKey } ` ) ;
101
103
next ( ) ;
102
104
} else if ( apiKey ) {
103
- debug ( 'auth' ) ( `Invalid API key: ${ apiKey } ` ) ;
105
+ debug ( `Invalid API key: ${ apiKey } ` ) ;
104
106
next ( new Unauthorized ( `Invalid API key: ${ apiKey } ` ) ) ;
105
107
} else {
106
- debug ( 'auth' ) ( ' Missing API key or Client Id') ;
108
+ debug ( 'Missing API key or Client Id' ) ;
107
109
next ( ) ;
108
110
}
109
111
}
0 commit comments