learning-jwt v1.0.0
learning-jwt
A guide about how to use JWT authentication and googleapis package.
Creating a Service Account using the Google Developers Console
From the Google Developers Console, select your project or create a new one.
Under "APIs & auth", click "Credentials".
Under "OAuth", click the "Create new client ID" button.
Select "Service account" as the application type and click "Create Client ID".
The key for your new service account should prompt for download automatically. Note that your key is protected with a password. IMPORTANT: keep a secure copy of the key, as Google keeps only the public key.
Download the json credentials too.
Convert the downloaded key (
some-file.p12
) to PEM, so we can use it from the Node crypto module.To do this, run the following in Terminal:
openssl pkcs12 -in downloaded-key-file.p12 -out your-key-file.pem -nodes
You will be asked for the password you received during step 5.
That's it! You now have a service account with an email address and a key that you can use from your Node application.
Installation
Clone the repository and install the dependencies:
$ git clone git@github.com:IonicaBizau/learning-jwt.git
$ cd learning-jwt
$ npm install
Now, let's set the credentials!
- Replace the
keyFile.pem
file with the generated file generated (your-key-file.pem
) in the previous step. - Set your data in
authData.json
as follows: email
: should be theclient_email
from downloaded json file.keyFile
: the path to the pem file. Don't modify it if you replaced thekeyFile.pem
file in the previous step.scopes
: are the authentication scopes (what rights you have when you are authenticated).
Then run:
$ node index.js
If everything went successfully, you should get the message You were successfully authenticated and see your credentials (tokens and so on).
How to contribute
Have an idea? Found a bug? See how to contribute.
License
KINDLY © Ionică Bizău–The LICENSE file contains a copy of the license.
8 years ago