This repository has a sample PubNub function that generates JSON Web Token for authorization to use Google Drive's Rest API.
- Sign Up for PubNub and create a new Project.
-
Copy and Paste the code from file completeAuth.js into a new PubNub function called completeAuth.
-
Create a service account that grants us the necessary permissions to access certain data stored on Google Cloud. To do this head over to your Google Cloud Console. Find your project or create a new one if you do not have one already. Then, inside your project, head to IAM and Admin then Service Accounts. Here click Create New Service Account and choose the role Service Account Admin. Select Furnish a new Private Key and once you create your service account, the console will download the JSON file with your private key onto your computer. Now we have successfully created the service account. Make sure to keep the JSON file with the service account credentials safe on your computer, as we will need these credentials later.
-
Enter the private key and service account email address where it says to insert them in the PubNub Functions code.
-
Create a new Sample Document, with the text, "This is a sample document!".
-
Find the document by using its file ID. In order to obtain the file ID of your document, navigate to your share button and it will be inside the URL.
-
In the getDriveFileURL insert this ID, where it says to.
-
Ensure that your PubNub functions module is running so that the server side code you have written is deployed and active.
-
Press the Get button to make a sample request to your PubNub function. It should log the body of the document, "This is a sample document!".