npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

jamalta-oidc-client

v0.9.91

Published

JA Malta OIDC Client for external/internal login-as implementation

Downloads

13

Readme

JA Malta OIDC Relying Party Module

Docs Release & Publish npm

This module is meant to be used when needing authentication with the JA Malta Platforms. The authentication, ran under the URI auth.jamalta.org, uses OpenID Connect specs and discovery url.

Please note that the authentication and this connector is still in the early alpha testing. Currently, this module is meant to be used internally until everything is tested.

This package can technically be used by other OIDC Providers but this was not tested and no support will be provided.

Feel free to open a PR and add/suggest features (no contribution guide yet).

Features

The connector has the following available features:

  1. Express Middleware to authenticate a token including a cache that lasts as long as the access-token.
  2. Session continuation after login is hit when token expiry
  3. UserInfo cache, to not constantly call the authentication endpoint everytime user info is needed.
  4. OpenID Discovery Specs

Assumptions

Cookie Middleware (such as cookie parser). ExpressJS being used

Getting Started

Getting started is pretty easy.

Installing the module

npm install jamalta-oidc-client

Creating the issuer

let issuer = new JAMaltaIssuer(clientId, clientSecret, redirectUris, responseTypes, scopes);

Getting the login url

Once the issuer is created, one can get the authorisation url by doing:

let url = await issuer.authorisationUrl;

Login Callback

From there onwards, create an express route with the callback and implement the callback middleware. The callback middleware creates a cookie on the frontend which can be read by the authentication middleware. The callback middleware also gets the cookie "before-callback-location", which stores the original location to redirect the user to their original location. This feature can be disabled by setting the useRedirect parameter to false.

expressApp.get("/callback", callbackMiddleware(issuer, true), (req, res) => {
    //your code here
    res.sendStatus(200);
});

Authentication Middleware

After initial authentication is done, the issuer does everything for you using the authentication middleware. In the case that the token is invalid, the user gets redirected to the login page and a cookie is created called "before-callback-location" so the backend knows where to redirect the user to.

expressApp.get("/your-endpoint", authenticate(issuer), (req, res) => {
    let userinfo = req.jaUserInfo;
    res.sendStatus(200);
})

The user info is then stored into the request as seen above, and can be used in any way needed.

Logout

The issuer also provides the functionality to logout easily by doing let url = await issuer.getLogoutUrl(token); The logout middleware is used to clear the token, and it's related user information from the cache, however, this is optional, considering you do the steps yourself. Not clearing the cache will result in the user seemingly staying authenticated until cache expires.

expressApp.get("/logout", authenticate(issuer), logoutMiddleware(issuer), (req, res) => {
   issuer.getLogoutUrl(req.tokenCode).then(value => res.redirect(value));
})

Developer Features

Custom Issuer URL

In the case that you are developing onto the OIDC Relay, and want to use a custom issuer URL, you can set the environment variable CUSTOM_ISSUER_URL which forces auto-discovery and endpoint binding to that OIDC Provider, assuming OIDC discovery is enabled on the OIDC Provider.