hapijs - What are authentication artifacts used for in hapi.js authentication schemes? -
in hapi.js api specify authentication schemes can return artifacts part of credentials object.
what authentication artifacts , why useful? there example why hapi team included part of api?
- result - object containing:
- credentials - authenticated credentials.
- artifacts - optional authentication artifacts.
short answer
on request.auth
have access following properties:
credentials
- things identify or represent unique userartifacts
- optional authentication-related data isn't credentials
hapi auth schemes aren't stateful can store important auth data in request.auth.artifacts
can accessed other auth functions in scheme @ later time.
what authentication artifacts?
first let's @ general definition of artifact (from wikipedia):
[artifacts] refer arises process in hand rather issue itself, i.e., result of interest stems means rather end.
an authentication scheme can optionally pass consuming application of internal information (byproducts) authentication attempt once it's finished authenticating request.
obviously data inside artifacts
different each scheme. when using hawk (with hapi-auth-hawk), artifacts object containing info specific hawk, such timestamp, nonce , mac code request:
{ method: 'get', host: '127.0.0.1', port: '8000', resource: '/resource/1?b=1&a=2', ts: '1426940961', nonce: 'ird0nh', hash: undefined, ext: 'and welcome!', app: undefined, dlg: undefined, mac: 'tkolc1uj5w8zgcdt6+knqfdhadjtf0/rdlozhtzucou=', id: 'dh37fgj292je' }
…why useful?
an example of why they're useful can found in hapi-auth-hawk. remember auth scheme in hapi can have 3 different functions called authentication:
authenticate
- required function authenticate initial requestpayload
- optionally validates payloadresponse
- optionally validates response
in hapi-auth-hawk, request.auth.artifacts
populated in authenticate
method initial request. means if payload
or response
executed later, can access same shared state off request
object without having parse request again, it's handy container pertinent auth data pulled request in case.
Comments
Post a Comment