Skip to main content

2 posts tagged with "proxy"

View All Tags

ยท 2 min read

grant is a nodejs OAuth proxy.

With few lines of code, grant can add oauth login support for any node.js app.

For example, Strapi uses grant to authenticate users via Oauth2.

This post explains how to use grant to authenticate Crossid.

Init a new project

mkdir grant-crossid && cd grant-crossid
npm -y init
npm install grant express express-session

Let crossid know about Grant

We need to let Crossid know about our grant app.

  • In Admin console, navigate to Integration โ†’ Marketplace
  • Choose Web App and click on Add Integration
  • Redirect URIs: http://localhost:3005/connect/crossid/callback

Grant your user access to this app.

  1. From the admin console, navigate to Applications -> Applications.
  2. Select your app.
  3. Click on the Users tab.
  4. Click the Add User Assignment button.
  5. Choose the created identity (e.g., Jared Dunn).
  6. Click Save.


Save the Client ID to the next deployment steps.


"defaults": {
"origin": "http://localhost:3005",
"transport": "session",
"state": true
"crossid": {
"subdomain": "acme",
"key": "<client_id>",
"secret": "<client_secret>",
"scope": ["openid"],
"callback": "/hello",
"response": ["tokens", "raw", "profile"]

The configuration file defines the crossid as an auth provider.

  • replace subdomain with your tenant.
  • replace <client_id> and <client_secret> with your app credentials.


var express = require("express");
var session = require("express-session");
var grant = require("grant").express();

.use(session({ secret: "grant", saveUninitialized: true, resave: false }))
.get("/hello", (req, res) => {
res.end(JSON.stringify(req.session.grant.response, null, 2));

Try it

Run the example by: node index.js

Open browser in https://localhost:3005/connect/crossid

You should be redirected to the login page, once user is logged in, you should see the access token and the user's profile.


ยท 3 min read

If you want to free yourself from coding authentication for your apps, or just want to servce protected files only for your users, a reverse proxy with identity awareness can be a good fit.

Such reverse proxy, like oauth2-proxy is able to authenicate users before forwarding the requests to your app.

The proxy enhances each request with headers that identifies the the authenticated user, so your app can simply reply on those headers to establish some identity context.

This post explains how to configure and run oauth2-proxy in a docker container and authenticate users by Crossid.


sequenceDiagram; autonumber Browser->>+Oauth2-Proxy: GET: /myapp Browser->>+Crossid: User not authenticated Crossid->>Crossid: User Signin Crossid->>Browser: User Session Created Browser->>App: GET /myapp Note right of App: forwarded-user:
  1. An anonymous visitor tries to access the app.
  2. oauth2-proxy has no session for the visitor, so it redirects the user to Crossid for login.
  3. Crossid asks the user to login.
  4. oauth2-proxy creates a session for the authenticated user.
  5. oauth2-proxy proxies the request to the app with some identity headers.

Let's get started!

Add oauth2-proxy integration

First, we need to tell Crossid about our oauth2-proxy.

Login to your existing crossid tenant or signup for free.

  • In Admin console, navigate to Integration โ†’ Marketplace
  • Choose oauth2-proxy and click on Add Integration
  • Follow wizard steps.
  • For this example, the redirect URL should be, which is where the oauth2-proxy is located.
  • Save client_id and client_secret for the next step.

Grant your user access to proxy

Lets grant your user access to the proxy.

  • In proxy's app page, navigate to Users tab and click the Add User Assignment button.
  • Select your user and press save.

httpbin as our app

For the sake of example, we use as our app. try clicking on it, it just renders our HTTP request as JSON.

Run oauth2-proxy

Lets configure and run oauth2-proxy in a docker container:

docker run --rm -p 4180:4180 \
-e OAUTH2_PROXY_OIDC_ISSUER_URL=https://<tenant> \
-e OAUTH2_PROXY_COOKIE_SECRET=someSecret123456 \
-e OAUTH2_PROXY_CLIENT_ID=<client_id> \
-e OAUTH2_PROXY_CLIENT_SECRET=<client_secret> \

Replace <tenant> with your tenant (e.g.,

Replace <client_id> and <client_secret> from previous step.

With this configuration, every request to will be proxied to the upstream (our app). We simply use that simply echos the request info.

Tip: for a random cookie secret run python -c 'import os,base64; print(base64.urlsafe_b64encode(os.urandom(16)).decode())'

Accessing our app

Navigate to should redirect user to crossid for login. Upon successful login, the request should be proxied to our app (

Partial response example:

"headers": {
"X-Forwarded-Email": "",
"X-Forwarded-User": "EN6vzb5dNBuc6fUAkYeKZ8"
"method": "GET",
"url": ""

X-Forwarded-User should be the crossid user id and X-Forwarded-Email should be user's email.



We have seen how we can free our app from auth complexity by lifting the auth complexity to oauth2-proxy.

For more info about oauth2-proxy, visit