Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

hydra-js

Package Overview
Dependencies
Maintainers
1
Versions
11
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

hydra-js

A client library for Hydra, an OAuth2 and OpenID Connect Provider

  • 0.1.5
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
75
decreased by-17.58%
Maintainers
1
Weekly downloads
 
Created
Source

hydra-js

Build Status Join the chat at https://gitter.im/ory/hydra Join mailinglist Join newsletter

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, // id of the client you want to use, defaults to this env var
   secret: process.env.HYDRA_CLIENT_SECRET, // secret of the client you want to use, defaults to this env var
 },
 auth: {
   tokenHost: process.env.HYDRA_URL, // hydra url, defaults to this env var
   authorizePath: '/oauth2/auth', // hydra authorization endpoint, defaults to '/oauth2/auth'
   tokenPath: '/oauth2/token', // hydra token endpoint, defaults to '/oauth2/token'
 },
 scope: 'hydra.keys.get' // scope of the authorization, defaults to '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(/* options */)
hydra.authenticate().then((token) => {
  // ...
}).catch((error) => {
  // ...
})

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(/* options */)

// verify consent challenge
hydra.verifyConsentChallenge(challenge).then(({ challenge: data }) => {
  // consent challenge is valid, render the consent screen:
  //  w.render('consent', { data })
}).catch((error) => {
  // error
})

// generate consent challenge
hydra.generateConsentResponse(challenge, subject, scopes, {}, data).then(({ consent }) => {
  // success! redirect back to hydra:
  //  w.redirect(challenge.redir + '&consent=' + consent)
}).catch((error) => {
  // error
})

FAQs

Package last updated on 19 Sep 2017

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc