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

micro-auth-request

v0.1.4

Published

Simple & fast authentication for Kubernetes ingress using Google OAuth2

Downloads

20

Readme

npm version License Coverage Status Build Status

micro-auth-request

micro-auth-request is a tiny service that helps you to decouple the authentication from the services behind reverse proxy or ingress. It's mainly designed to be used by Nginx or nginx-ingress (for Kubernetes) as reverse-proxy and Google as the authentication provider but you can also use it with other reverse proxies like Traefik for your microservices or monolith.

You can use micro-auth-request just by providing Google client ID and secret without the need to set up any other tools. But if you need something more, for example, if you want to also include roles of the user you need to add it manually. We believe in Convention over configuration it's easier to add a Javascript file rather than complicated limited configuration files.

How it works?

nginx auth_request implements client authorization based on the result of a subrequest. The procedure is fairly simple, for any income request, nginx redirect the header of that request to micro-auth-request, based on the request headers (token, cookie, ...), it makes decistion if the user is authenticate or not. The original request will pass to the original service only if micro-auth-request return 200 to nginx. If authentication is required, micro-auth-request helps to use google for it and manage the procedure automatically.

How to setup?

There are many ways to run micro-auth-request in your production environment.

Using npm

GOOGLE_CLIENT_ID=<YOUR_CLIENT_ID> GOOGLE_CLIENT_SECRET=<YOUR_CLIENT_SECRET> npx micro-auth-request

Using docker

docker run -d -e OOGLE_CLIENT_ID=<YOUR_CLIENT_ID> -e GOOGLE_CLIENT_SECRET=<YOUR_CLIENT_SECRET> -p 8080:8080 abdollahpour/micro-auth-request

Using HELM for kubernetes

Or if you are using kubernetes, using HELM:

helm repo add micro-auth-request 'https://raw.githubusercontent.com/abdollahpour/micro-auth-request-helm/master/'
helm repo update
helm install \
    --set google.clinet_id=<YOUR_CLIENT_ID> \
    --set google.clinet_secret=<YOUR_CLIENT_SECRET> \
    --set ingress.enable=true \
    --set ingress.hosts[0]=yourdomain.com \
    micro-auth-request micro-auth-request

for more information please visit the helm chart.

How to use it?

Using micro-auth-request you can cover four scenarios:

  • User is authenticated, he can access the service behind the proxy.
  • User is not authenticated, you want to redirect it to the login page (good for HTMLs).
  • User is not authenticated, you want to return 401.
  • User is not authenticated, but you still want to give him the access, but the service detects that there's no user signed in. An example usecase if a search engine, if a user is authenticated you want to customize the search result based on his profile, and if not, nothing will happen and we may use some other things, for example, IP or location.

Check the example directory for more information.

How to add more?

If you want to enrich the user info (add roles for example), you can edit src/controller/redirect and easily fetch more information from another service of the database.

If you need another authentication provider rather than Google, implement a new one. Copy src/service/google.js and use if as boilerplate for your own service. Then switch to it on src\middleware\oauth.js.