Skip to content

Commit cfeff26

Browse files
committed
add examples
1 parent b823c91 commit cfeff26

File tree

1 file changed

+11
-7
lines changed

1 file changed

+11
-7
lines changed

README.md

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
## Introduction
1818
**hapi-auth-keycloak** is a plugin for [hapi.js](hapijs] which enables to protect your endpoints in a smart but professional manner using [Keycloak][keycloak] as authentication service. It is inspired by the related [express.js middleware][keycloak-node]. The plugin validates the passed [`Bearer` token][bearer] online with help of the [Keycloak][keycloak] server and optionally caches successfully validated tokens and the related user data using [`catbox`][catbox]. The caching enables a fast processing although the user data don't get changed until the token expires. It plays well with the [hapi.js][hapijs]-integrated [authentication feature][hapi-route-options]. Besides the authentication strategy it is possible to validate tokens by yourself, e.g. to authenticate incoming websocket or queue messages.
1919

20-
This plugin is implemented in ECMAScript 6 without any transpilers like `babel`.<br/>
20+
This plugin is implemented in ECMAScript 6 without any transpilers like [`babel`][babel].<br/>
2121
Additionally [`standard`][standardjs] and [`ava`][avajs] are used to grant a high quality implementation.<br/>
2222

2323
## Installation
@@ -61,7 +61,9 @@ server.register({
6161
register: authKeycloak,
6262
options: {
6363
client: {
64-
// ...
64+
realmUrl: 'https://localhost:8080/auth/realms/testme',
65+
clientId: 'foobar',
66+
secret: '1234-bar-4321-foo'
6567
},
6668
cache: {}
6769
}
@@ -112,18 +114,17 @@ Required.
112114
If `false` the cache is disabled. Use an empty object to use the built-in default cache.<br/>
113115
Optional. Default: `false`.<br/>
114116

115-
#### `server.kjwt.validate(field <string>, done <Function>)`
117+
#### `server.kjwt.validate(field {string}, done {Function})`
116118
Uses internally [`GrantManager.prototype.validateAccessToken()`][keycloak-auth-utils-gm-validate].
117119

118-
- `field {string}`: The `Bearer` field, including the scheme itself.<br/>
120+
- `field {string}`: The `Bearer` field, including the scheme (`bearer`) itself.<br/>
119121
Example: `bearer 12345.abcde.67890`.<br/>
120122
Required.
121123

122-
- `done {Function}`: The callback handler is passed an `Error` object (if available) and the `result` (error-first). If the token is invalid, the `result` is `false`. Otherwise it is an object containing all relevant credentials.<br/>
124+
- `done {Function}`: The callback handler is passed `err {Error}, result {Object|false}` (error-first approach).<br/>If an error occurs, `err` is not `null`. If the token is invalid, the `result` is `false`. Otherwise it is an object containing all relevant credentials.<br/>
123125
Required.
124126

125127
## Example
126-
#### Code
127128

128129
``` js
129130
const Hapi = require('hapi');
@@ -161,7 +162,9 @@ server.register({
161162
register: authKeycloak,
162163
options: {
163164
client: {
164-
// ...
165+
realmUrl: 'https://localhost:8080/auth/realms/testme',
166+
clientId: 'foobar',
167+
secret: '1234-bar-4321-foo'
165168
},
166169
cache: {}
167170
}
@@ -204,6 +207,7 @@ For further information read the [contributing guideline](CONTRIBUTING.md).
204207
[hapijs]: https://hapijs.com/
205208
[avajs]: https://github.com/avajs/ava
206209
[standardjs]: https://standardjs.com/
210+
[babel]: https://babeljs.io/
207211
[npm]: https://github.com/npm/npm
208212
[yarn]: https://yarnpkg.com
209213
[jwt]: https://jwt.io/

0 commit comments

Comments
 (0)