0.1.2 • Published 4 years ago

@rtbhouse/google-iap-auth v0.1.2

Weekly downloads
-
License
MIT
Repository
github
Last release
4 years ago

@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);
})();
0.1.2

4 years ago

0.1.1

4 years ago

0.1.0

4 years ago