Skip to content
This repository has been archived by the owner on Mar 28, 2024. It is now read-only.

Helper library to perfrorm requests to OIDC-authenticated resources (Cloud Identity-Aware Proxy)

License

Notifications You must be signed in to change notification settings

rtbhouse-apps/google-iap-auth-nodejs

Repository files navigation

@rtbhouse/google-iap-auth

Helper library to perfrorm requests to OIDC-authenticated resources (Cloud Identity-Aware Proxy)

Installation

npm install @rtbhouse/google-iap-auth

Usage

To use this library you must have the following:

  • Identity Aware Proxy protected resource
  • Service account with permissions to read protected resource
  • OAuth credentials with key file in JSON format ( more on generating Service Account json keys)

Example usage with got:

import fs from 'fs';
import got from "got";
import { GoogleIapAuth } from "@rtbhouse/google-iap-auth";


const keyStr = fs.readFileSync('key.json', 'utf-8');
const keyData = JSON.parse(keyStr);
const googleIapAuth = new GoogleIapAuth("<oauth_client_id>", keyData);
const authorizedGot = got.extend({
  hooks: {
    beforeRequest: [
      async options => {
        options.headers.Authorization = `Bearer ${await googleIapAuth.getToken()}`;
      }
    ]
  },
  responseType: "json",
  followRedirect: false,
  mutableDefaults: true
});

(async () => {
  const response = await authorizedGot(
    "https://some.iap.protected.resource.com/"
  );
  console.log(response.statusCode);
  console.log(response.body);
})();

About

Helper library to perfrorm requests to OIDC-authenticated resources (Cloud Identity-Aware Proxy)

Resources

License

Stars

Watchers

Forks

Packages

No packages published