@byu-oit/hydra-client
A client library for talking with the BYU ORY Hydra instance
Last updated a year ago by gi60s .
Apache-2.0 · Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install @byu-oit/hydra-client 
SYNC missed versions from official npm registry.

Hydra Client

This package includes a functional API for making requests against BYU's ORY Hydra implementation.

Installation

npm install @byu-oit/hydra-client

API

Constructor

new HydraClient (config): Object

Constructs a HydraClient instance.

Parameters

  • config - A required configuration object with the following required properties:

    • baseUrl - The base URL to use to connect to the hydra server.

    • clientId - The client ID to use to access administrative features on the hydra server.

    • clientSecret - The client secret to use to access administrative features on the hydra server.

Returns an instance of the BYU Hydra Client.

Example

const HydraClient = require('@byu-oit/hydra-client')
const client = new HydraClient({
  baseUrl: 'https://my-hydra-domain.com:4455',
  clientId: 'client_id',
  clientSecret: 'a super secret secret'
})

Methods

HydraClient.prototype.authorizationMiddleware

authorizationMiddleware (options): Function

Produce an express middleware function that will look for authorization credentials, validate and decode them, and attach them to the request object as the oauth property. The value attached to the oauth property is the same as that returned by calling the introspection function.

Parameters

  • options - An object with these properties:

    • authorizationRequired - Whether the middleware requires authorization. If set to true then a valid authorization bearer token must be provided. If set to false then the authorization header may be omitted. Regardless of this setting, if an authorization header is provided then it must be valid. Defaults to true.

    • fallthrough - Set to true to have authorization errors call the next error handling middleware. If set to false then a response will be sent instead. Defaults to false.

Returns a middleware function.

Example

const app = express()
const client = new HydraClient(config)

app.use(client.authorizationMiddleware())

app.get('/', (req, res) => {
  if (req.oauth.user) {
    res.send('You are using a code grant token')
  } else {
    res.send('You are using a client grant token')
  }
})

app.listen(3000)

HydraClient.prototype.introspection

introspection (token): Promise<Object>

Introspect a token to determine the client information, user information (where applicable), and scopes.

Parameters

  • token - An access token to get introspection from.

Returns A promise that resolves to an object with these properties:

  • client - An object containing client information, including:

    • id - The client ID.

    • owner - The client owner name.

  • scopes - An array of the scopes granted to the token.

  • user - An object containing user information. This property only exists when a user is tied to the token. Includes the properties:

    • ces_id - The CES id of the user

Example

const client = new HydraClient(config)
client.introspection('<access_token>')
  .then(introspection => {
    console.log(introspection)
    /*
    { 
      client: {
        id: 'client-id',
        owner: 'owner-name'
      },
      scopes: [ 'scope-one', 'scope-two' ],
      user: {
        ces_id: '123456789'
      }
    }
    */
  })

Current Tags

  • 0.0.5                                ...           latest (a year ago)

4 Versions

  • 0.0.5                                ...           a year ago
  • 0.0.4                                ...           a year ago
  • 0.0.3                                ...           a year ago
  • 0.0.2                                ...           a year ago
Downloads
Today 0
This Week 0
This Month 5
Last Day 0
Last Week 4
Last Month 0
Dependencies (3)
Dev Dependencies (3)
Dependents (0)
None

Copyright 2014 - 2016 © taobao.org |