Natural Preference for Minification
    Wondering what’s next for npm?Check out our public roadmap! »

    @rtbhouse/google-iap-auth
    TypeScript icon, indicating that this package has built-in type declarations

    0.1.2 • Public • Published

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

    Install

    npm i @rtbhouse/google-iap-auth

    DownloadsWeekly Downloads

    3

    Version

    0.1.2

    License

    MIT

    Unpacked Size

    9.5 kB

    Total Files

    9

    Last publish

    Collaborators

    • avatar
    • avatar
    • avatar