Intended as an example for utilizing Google APIs.
npm install
npm install -g foreman # Install foreman globally
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": ""
}
}
}
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
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'];
npm run start
npm run develop # With nodemon