hydra-js
Hydra is a runnable server implementation of the OAuth2 2.0 authorization framework and the OpenID Connect Core 1.0.
Hydra-js is a client library for javascript. It is currently available as an npm-module only. At this moment, Hydra-js
primarily helps you with performing the consent validation.
We welcome contributions that implement more of the Hydra HTTP REST API.
Installation
$ npm i --save hydra-js
Examples
Instantiating
var Hydra = require('hydra-js')
const config = {
client: {
id: process.env.HYDRA_CLIENT_ID,
secret: process.env.HYDRA_CLIENT_SECRET,
},
auth: {
tokenHost: process.env.HYDRA_URL,
authorizePath: '/oauth2/auth',
tokenPath: '/oauth2/token',
},
scope: 'hydra.keys.get'
}
const hydra = new Hydra(config)
Getting an access token with the client_credentials flow
var Hydra = require('hydra-js')
const hydra = new Hydra()
hydra.authenticate().then((token) => {
}).catch((error) => {
})
Consent flow
The following examples fetches the appropriate cryptographic keys and access tokens automatically, you basically need to do:
var Hydra = require('hydra-js')
const hydra = new Hydra()
hydra.verifyConsentChallenge(challenge).then(({ challenge: data }) => {
}).catch((error) => {
})
hydra.generateConsentResponse(challenge, subject, scopes, {}, data).then(({ consent }) => {
}).catch((error) => {
})