1// STEP 1. Install dependencies and make config.js
2// project for understanding google authorization with express
3//set up your Node.JS project, and install the following dependencies:
4// cookie-parser
5// ejs
6// express
7// google-auth-library
8// googleapis
9// jsonwebtoken
10// In the Credentials section of the Google Developer Console,
11// create an OAuth Client ID credential of type Web Application.
12// Create a file named config.js with the following contents,
13// Fill in the client_id, project_id, and client_secret properties
14// with the information for your project.
15////////////////////////// config.js
16
17const port = 3002;
18const baseURL = `http://localhost:${port}`;
19module.exports = {
20 // The secret for the encryption of the jsonwebtoken
21 JWTsecret: 'mysecret',
22 baseURL: baseURL,
23 port: port,
24 // The credentials and information for OAuth2
25 oauth2Credentials: {
26 client_id: "",
27 project_id: "", // The name of your project
28 auth_uri: "https://accounts.google.com/o/oauth2/auth",
29 token_uri: "https://oauth2.googleapis.com/token",
30 auth_provider_x509_cert_url: "https://www.googleapis.com/oauth2/v1/certs",
31 client_secret: "",
32 redirect_uris: [
33 `${baseURL}/auth_callback`
34 ],
35 scopes: [
36 'https://www.googleapis.com/auth/youtube.readonly'
37 ]
38 }
39};
40
1// STEP 4. ///////////////////////////////////////////////
2// Lastly create the data.ejs template in order
3// to display the data.
4//////////////////////////////////////////////////////////
5
6
7<!DOCTYPE html>
8<html lang="en">
9<head>
10 <meta charset="UTF-8">
11 <meta name="viewport" content="width=device-width, initial-scale=1.0">
12 <meta http-equiv="X-UA-Compatible" content="ie=edge">
13 <title>Express Google OAuth2 Tutorial by Aidan Lovelace</title>
14</head>
15<body>
16 <ul>
17 <% subscriptions.forEach(function (subscription) { %>
18 <li><%= subscription.snippet.title %></li>
19 <% }) %>
20 </ul>
21</body>
22</html>
23