1.0.0 • Published 8 years ago

learning-jwt v1.0.0

Weekly downloads
2
License
MIT
Repository
github
Last release
8 years ago

learning-jwt Donate now

A guide about how to use JWT authentication and googleapis package.

Creating a Service Account using the Google Developers Console

  1. From the Google Developers Console, select your project or create a new one.

  2. Under "APIs & auth", click "Credentials".

  3. Under "OAuth", click the "Create new client ID" button.

  4. Select "Service account" as the application type and click "Create Client ID".

  5. 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.

  6. Download the json credentials too.

  7. 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.

Source. Thanks!

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 the client_email from downloaded json file.
  • keyFile: the path to the pem file. Don't modify it if you replaced the keyFile.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.