This repository has been archived by the owner on Mar 28, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add Google IAP auth implementation (#1)
* add Google IAP auth implementation
- Loading branch information
1 parent
9b17487
commit 01f8a86
Showing
11 changed files
with
6,035 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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'] | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
})(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"] | ||
} |
Oops, something went wrong.