Giter Club home page Giter Club logo

hydra-auth0-consent-sdk's Introduction

hydra-consent-app-auth0

THIS REPOSITORY IS DEPRECATED

This repository contains a library and an exemplary express application that connects ORY Hydra with Auth0.

CircleCI

Introduction

Setting up Auth0

Once you create an Auth0 account and an Auth0 tenant, you need to create a new client that the consent app will use to connect to Auth0.

Create a new Auth0 Client

Once created, go to the Settings tab and use the client ID, client secret and domain fields to populate the environment variables AUTH0_CLIENT_ID, AUTH0_CLIENT_SECRET, AUTH0_DOMAIN.

Copy Auth0 Client Credentials

To get this specific demo working, you also need to add a callback url pointing to http://localhost:4446/auth/callback, as that is the callback url the Docker demo is using.

Set Auth0 Client Callback URL

Running the Demo

Now that you have set the environment variables it is time to run the demo. Make sure to have docker and docker-compose installed, then run:

docker-compose -p auth0consent up --build

Once all the services are booted, use the following CLI command to perform the OAuth 2.0 authorize code flow.

$ docker rm -f auth0consent_hydra_token; docker run \
    --name auth0consent_hydra_token \
    --rm \
    -p 4445:4445 \
    --network auth0consent_subnet \
    oryd/hydra:v0.10.0-alpha.18 \
    token user \
        --auth-url=http://localhost:4444/oauth2/auth \
        --token-url=http://hydra:4444/oauth2/token \
        --id root \
        --secret secret \
        --no-open \
        --scopes offline,openid

Docs

This repository has two packages, ory-hydra-auth0-consent-sdk which contains a few helpers to deal with the consent flow, and an exemplary app.

You may use the example app as guidance, or fork it to create your own consent app.

SDK

First we need to initialize passport, luckily the SDK provides a helper for that:

var consent = require('ory-hydra-consent-sdk');
var winston = require('winston'); // We recommend using winston for logging

var initializePassport = consent.initializePassport;

initializePassport(passport, winston)

To get the SDK working in an express app, we have to load certain express middleware, such as a body parser, a session middleware, passport middleware, and so on. To make this as easy as possible, a helper is provided that can solve this for you:

var express = require('express');
var consent = require('ory-hydra-consent-sdk');

var initializeMiddleware = consent.initializeMiddleware;
var app = express();

app.use(logger('dev')); // Load some middlewares, such as request logging
app.use(express.static(path.join(__dirname, '..', 'public'))); // Or static file serving

initializeMiddleware(app, passport); // Loads the required middlewares for the SDK to work

Once everything is initialized, it is time to define the login, callback and consent routes. For an example of how to do that, please browse this documented source file.

Example App

The example app supports the following environments for configuration:

Environment variable Description Required Default
AUTH0_CLIENT_ID The Auth0 Client ID Yes ``
AUTH0_CLIENT_SECRET The Auth0 Client Secret Yes ``
AUTH0_DOMAIN The Auth0 Domain Yes ``
AUTH0_CALLBACK_URL The callback url of your consent app, which must be whitelisted in the Auth0 client setting Yes ``
HYDRA_CLIENT_ID The OAuth 2.0 Client ID capable of accessing ORY Hydra's /oauth2/consent/requests endpoint Yes ``
HYDRA_CLIENT_Secret The OAuth 2.0 Client secret for access ORY Hydra Yes ``
HYDRA_URL The URL of ORY Hydra Yes ``
COOKIE_SECRET The secret used to encrypt session values No uuid.v4()
DEFAULT_REDIRECT_URL Allows the user to continue when an error occurs No ``
LOG_LEVEL Set this to debug for seeing what is going on in your app No info

hydra-auth0-consent-sdk's People

Contributors

aeneasr avatar arekkas avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

hydra-auth0-consent-sdk's Issues

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.