GithubHelp home page GithubHelp logo

isabella232 / hydra-js Goto Github PK

View Code? Open in Web Editor NEW

This project forked from segment-boneyard/hydra-js

0.0 0.0 0.0 16 KB

A simple library to help you build node-based identity providers that work with Hydra.

JavaScript 100.00%

hydra-js's Introduction

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) => {
  // ...
})

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

hydra-js's People

Contributors

arekkas avatar danielsmedegaardbuus avatar eliasgs avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.