@@ -38,7 +38,28 @@ const scheme = joi.object({
38
38
. example ( 'true' ) ,
39
39
userInfo : joi . array ( ) . items ( joi . string ( ) . min ( 1 ) )
40
40
. description ( 'List of properties which should be included in the `request.auth.credentials` object' )
41
- . example ( [ 'name' , 'email' ] )
41
+ . example ( [ 'name' , 'email' ] ) ,
42
+ apiKey : joi . object ( {
43
+ in : joi . string ( ) . valid ( 'headers' , 'query' ) . default ( 'headers' )
44
+ . description ( 'Whether the api key is placed in the header or query' )
45
+ . example ( 'query' ) ,
46
+ name : joi . string ( ) . min ( 1 ) . default ( 'authorization' )
47
+ . description ( 'The name of the related header field or query key' )
48
+ . example ( 'x-api-key' ) ,
49
+ prefix : joi . string ( ) . min ( 1 ) . default ( 'Api-Key ' )
50
+ . description ( 'An optional prefix of the related api key value' )
51
+ . example ( 'Apikey ' ) ,
52
+ url : joi . string ( ) . min ( 1 ) . required ( )
53
+ . description ( 'The absolute url to be requested' )
54
+ . example ( 'https://foobar.com/api' ) ,
55
+ request : joi . object ( ) . default ( { } )
56
+ . description ( 'The detailed request options for `got`' )
57
+ . example ( { retries : 2 } ) ,
58
+ tokenPath : joi . string ( ) . min ( 1 ) . default ( 'access_token' )
59
+ . description ( 'The path to the access token in the response its body' )
60
+ . example ( 'foo.bar' )
61
+ } ) . unknown ( false )
62
+ . description ( 'The configuration of an optional api key strategy interaction with another service' )
42
63
} )
43
64
. without ( 'entitlement' , [ 'secret' , 'publicKey' ] )
44
65
. without ( 'secret' , [ 'entitlement' , 'publicKey' ] )
@@ -94,9 +115,10 @@ function verify (opts) {
94
115
* @param {string } [scheme = 'Bearer'] The related scheme
95
116
* @returns {Boom.unauthorized } The created `Boom` error
96
117
*/
97
- function raiseUnauthorized ( err , msg , scheme = 'Bearer' ) {
118
+ function raiseUnauthorized ( err , msg , reason , scheme = 'Bearer' ) {
98
119
return boom . unauthorized ( err ? err . message : msg , scheme , {
99
- strategy : 'keycloak-jwt'
120
+ strategy : 'keycloak-jwt' ,
121
+ ...( reason ? { reason } : { } )
100
122
} )
101
123
}
102
124
@@ -109,7 +131,8 @@ function raiseUnauthorized (err, msg, scheme = 'Bearer') {
109
131
const errorMessages = {
110
132
invalid : 'Invalid credentials' ,
111
133
missing : 'Missing or invalid authorization header' ,
112
- rpt : 'Retrieving the RPT failed'
134
+ rpt : 'Retrieving the RPT failed' ,
135
+ apiKey : 'Retrieving the token with the api key failed'
113
136
}
114
137
115
138
/**
0 commit comments