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

Commit

Permalink
add Google IAP auth implementation (#1)
Browse files Browse the repository at this point in the history
* add Google IAP auth implementation
  • Loading branch information
jacek-jablonski authored Jan 20, 2020
1 parent 9b17487 commit 01f8a86
Show file tree
Hide file tree
Showing 11 changed files with 6,035 additions and 1 deletion.
9 changes: 9 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
root = true

[*]
charset = utf-8
indent_style = space
indent_size = 2
end_of_line = lf
insert_final_newline = true
trim_trailing_whitespace = true
31 changes: 31 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
module.exports = {
'env': {
'es6': true,
'node': true
},
'extends': [
'eslint:recommended',
'plugin:@typescript-eslint/eslint-recommended'
],
'globals': {
'Atomics': 'readonly',
'SharedArrayBuffer': 'readonly'
},
'parser': '@typescript-eslint/parser',
'parserOptions': {
'ecmaVersion': 2017,
'sourceType': 'module'
},
'plugins': [
'@typescript-eslint'
],
'ignorePatterns': ['dist/', 'node_modules/'],
'rules': {
'max-len': ['error', { 'code': 120 }],
'no-unused-vars': ['error', { 'args': 'none' }],
'indent': ['error', 2],
'linebreak-style': ['error', 'unix'],
'quotes': ['error', 'single'],
'semi': ['error', 'always']
}
};
51 changes: 50 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,51 @@
# google-iap-auth-nodejs
# @rtbhouse/google-iap-auth

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

## Installation

```shell
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](https://cloud.google.com/iam/docs/creating-managing-service-account-keys#iam-service-account-keys-create-console)
on generating Service Account json keys)

Example usage with [got](https://www.npmjs.com/package/got):

```typescript
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);
})();
6 changes: 6 additions & 0 deletions jestconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"preset": "ts-jest",
"rootDir": "./tests",
"testMatch": ["<rootDir>/**/*.ts"],
"moduleFileExtensions": ["ts", "tsx", "js", "jsx", "json", "node"]
}
Loading

0 comments on commit 01f8a86

Please sign in to comment.