Skip to content

nealfennimore/google-api-node-express

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

27 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Google API Express Server

Intended as an example for utilizing Google APIs.

Installation

npm install
npm install -g foreman # Install foreman globally

.env File Example

Update your .env file to look similar.

{
    "server": {
        "ip": "0.0.0.0",
        "port": 3000
    },
    "auth": {
        "secret": "YourSecretHere", /* Add your public key here for RS256 */
        "algorithm": "HS256" /* or RS256, etc. */
    },
    "google": {
        "auth": {
            /* Your Google JSON Secret */
        },
        "api": {
            /* Deliminate scopes with a comma */
            "scopes": "https://www.googleapis.com/auth/calendar,https://www.googleapis.com/auth/drive"
        },
        "calendar": {
            "id": ""
        }
    }
}

Generate Keys

We'll use a either a secret key or RSA public key for verifying using JSON Web Tokens for certain API requests. Generate a private and public key using the below commands for RS256.

# RS256 key
openssl genrsa -out keys/priv.pem 1024
openssl rsa -pubout -in keys/priv.pem -out keys/pub.pem

Get Access Token

Generate an access token and use it for authenticated API requests.

# RS256
const privateKey = fs.readFileSync('keys/priv.pem');
const RS_256_ACCESS_TOKEN = jwt.sign({}, privateKey, { algorithm: 'RS256'})

# HS256
const HS256_ACCESS_TOKEN = jwt.sign({}, AUTH_SECRET);

The token should be in the Authorization Header.

// Authorization: Bearer <token>
req.headers['authorization'];

Starting API Server

npm run start
npm run develop # With nodemon

Releases

No releases published

Packages

No packages published