0.0.2 • Published 4 years ago

@fmpanelli/generate-jwt v0.0.2

Weekly downloads
1
License
ISC
Repository
-
Last release
4 years ago

generate-jwt

Little utility to generate a Google JWT access token for testing.

Prerequisites

Just Node.

Getting Started

Iaaa

Setup of your local environment

.env file

The setup of your local enviroment is done with the .env file. This is a file where you can specify enviroment variables that will be loaded into node.js when running locally.

You can find a .env.example in the git repo. Copy it to .env and adjust it to your needs. The file .env will be ignored by git.

The project is setup in a way such that the .env configuration will be used for all local needs, i.e.:

  • running tests when you hit npm test
  • running tests within VS Code (I use Jest extension by Orta)
  • running a local server, which you can do by npm run local_server

Note: you can also setup the same variables from the command line and, actually, if the variables are set from the CLI, the corresponding values in .env file will be ignored.

I found two tricky points in using env variables set in CLI:

  1. you have to setup the variables before launching vscode in order for them to be visible by vscode extensions
  2. terminals launched within vscode will not inherit those variables

Prepare for Google authentication

The first step is creating a Google Service Account, that is a technical account on GCP, and giving you local node.js the credentials to login with that account:

  • create a Google service account
  • create a key im json format
  • download the json and save it here under ./credentials folder (it will be ignored by Git)
  • set the enviroment variables (possibly using .env)
    • GCLOUD_PROJECT
    • GOOGLE_APPLICATION_CREDENTIALS

The second step is to grant your service account access to the Spreadsheet it needs access: simply open the spreadsheet click on share and type the email address of the service account.

Oh, my proxy!

When running inside Credem's network you may encounter several obstacles dealing with the proxy.

As of Feb 2020 the following works for me:

  • For googleapis library to work correctly you should have HTTP_PROXY and HTTPS_PROXY set to http://proxyre02.group.credem.net:8080 (possibly using .env)
  • You should point Internet Exporer or another proxy to the same proxy and authenticate.
  • The authentication will last for 15 minutes for the shole machine. So be sure to visit a new page in IE every 15 minutes.

Testing

Test is done with jest and ts-jest.