@@ -3,7 +3,7 @@ const { GrantManager } = require('keycloak-auth-utils')
3
3
const KeycloakToken = require ( 'keycloak-auth-utils/lib/token' )
4
4
const cache = require ( './cache' )
5
5
const token = require ( './token' )
6
- const { raiseError , errors, fakeToolkit, verify } = require ( './utils' )
6
+ const { raiseUnauthorized , errors, fakeToolkit, verify } = require ( './utils' )
7
7
const pkg = require ( '../package.json' )
8
8
9
9
/**
@@ -45,7 +45,7 @@ async function verifySignedJwt (tkn) {
45
45
* @param {string } tkn The token to be validated
46
46
* @returns {Promise } The error-handled promise
47
47
*
48
- * @throws {Error } If token is invalid or request fails
48
+ * @throws {Error } If token is invalid or request failed
49
49
*/
50
50
async function introspect ( tkn ) {
51
51
try {
@@ -67,7 +67,7 @@ async function introspect (tkn) {
67
67
* @param {string } tkn The token to be used for authentication
68
68
* @returns {Promise } The modified, non-error-handling promise
69
69
*
70
- * @throws {Error } If request failed or token is invalid
70
+ * @throws {Error } If token is invalid or request failed
71
71
*/
72
72
async function getRpt ( tkn ) {
73
73
let data = { }
@@ -109,7 +109,7 @@ function getValidateFn () {
109
109
* @param {string } tkn The token to be validated
110
110
* @param {Function } h The toolkit
111
111
*
112
- * @throws {Boom.unauthorized } If validation fails
112
+ * @throws {Boom.unauthorized } If previous validation fails
113
113
*/
114
114
async function handleKeycloakValidation ( tkn , h ) {
115
115
try {
@@ -120,7 +120,7 @@ async function handleKeycloakValidation (tkn, h) {
120
120
await cache . set ( store , tkn , userData , expiresIn )
121
121
return h . authenticated ( userData )
122
122
} catch ( err ) {
123
- throw raiseError ( 'unauthorized' , err , errors . invalid )
123
+ throw raiseUnauthorized ( err , errors . invalid )
124
124
}
125
125
}
126
126
@@ -142,7 +142,7 @@ async function validate (field, h = (data) => data) {
142
142
const reply = fakeToolkit ( h )
143
143
144
144
if ( ! tkn ) {
145
- throw raiseError ( 'unauthorized' , null , errors . missing )
145
+ throw raiseUnauthorized ( null , errors . missing )
146
146
}
147
147
148
148
const cached = await cache . get ( store , tkn )
@@ -180,7 +180,7 @@ function strategy (server) {
180
180
* @param {Hapi.Server } server The created server instance
181
181
* @param {Object } opts The plugin related options
182
182
*/
183
- function plugin ( server , opts ) {
183
+ function register ( server , opts ) {
184
184
options = verify ( opts )
185
185
manager = new GrantManager ( options )
186
186
store = cache . create ( server , options . cache )
@@ -189,7 +189,4 @@ function plugin (server, opts) {
189
189
server . decorate ( 'server' , 'kjwt' , { validate } )
190
190
}
191
191
192
- module . exports = {
193
- register : plugin ,
194
- pkg
195
- }
192
+ module . exports = { register, pkg }
0 commit comments