Skip to content

Commit d6e303a

Browse files
committed
add scheme for api key options
1 parent 855857a commit d6e303a

File tree

1 file changed

+27
-4
lines changed

1 file changed

+27
-4
lines changed

src/utils.js

Lines changed: 27 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,28 @@ const scheme = joi.object({
3838
.example('true'),
3939
userInfo: joi.array().items(joi.string().min(1))
4040
.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')
4263
})
4364
.without('entitlement', ['secret', 'publicKey'])
4465
.without('secret', ['entitlement', 'publicKey'])
@@ -94,9 +115,10 @@ function verify (opts) {
94115
* @param {string} [scheme = 'Bearer'] The related scheme
95116
* @returns {Boom.unauthorized} The created `Boom` error
96117
*/
97-
function raiseUnauthorized (err, msg, scheme = 'Bearer') {
118+
function raiseUnauthorized (err, msg, reason, scheme = 'Bearer') {
98119
return boom.unauthorized(err ? err.message : msg, scheme, {
99-
strategy: 'keycloak-jwt'
120+
strategy: 'keycloak-jwt',
121+
...(reason ? { reason } : {})
100122
})
101123
}
102124

@@ -109,7 +131,8 @@ function raiseUnauthorized (err, msg, scheme = 'Bearer') {
109131
const errorMessages = {
110132
invalid: 'Invalid credentials',
111133
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'
113136
}
114137

115138
/**

0 commit comments

Comments
 (0)