Giter VIP home page Giter VIP logo

hapi-oidc's Introduction

Hapi-OIDC

OpenID-Connect authentication plugin for hapi.

Configuration

This plugin needs some configuration to discover and connect to the OIDC server:

  • discoverUrl: The discovery URL of your OIDC server
  • clientId: Client ID given by your OIDC server
  • clientSecret: Client secret given by your OIDC server
  • callbackUrl: The full URL that the server will call after the authorization process
  • [cookie]: Name of the cookie that will held the authentication. Defaults to hapi-oidc

Alternatively, you can manually setup your OIDC client by replacing the discover URL by:

  • issuer: URL of the issuer
  • authorization: Authorization endpoint
  • token: Token generation endpoint
  • userinfo: User infos endpoint
  • jwks: JWKS endpoint

When registering the oidc scheme, you'll need to configure the cookie settings if defaults do not suits you:

  • password=uuid4(),
  • [path='/']
  • [ttl= 3600 * 1000]
  • [encoding='iron']
  • [isSecure=true],
  • [clearInvalid=true]

Example

const Hapi = require('hapi');
const uuid4 = require('uuid/v4');
const OIDC = require('hapi-oidc');

const routes = require('./routes');

const server = Hapi.server({
  port: 3000,
});

const init = async () => {
  await server.register([
    {
      plugin: OIDC,
      options: {
        discoverUrl: 'https://oidc-server.com/oauth2/default',
        clientId: 'XXXXXXXXXXXXXXX',
        clientSecret: 'XXXXXXXXXXXXXXXXXXXXXX',
        callbackUrl: 'https://my-server:3000/login_callback',
      },
    }
  ]);

  server.auth.strategy('oidc', 'oidc', {
    password: uuid4(),
  });

  server.route(routes);
  await server.start();
  server.log(['info'], `Server running at: ${server.info.uri}`);
};

init();

module.exports = server;

hapi-oidc's People

Contributors

dependabot[bot] avatar jbips avatar ulrikstrid avatar

Stargazers

 avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  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.