Removed the Auth0 env file from the server
This commit is contained in:
1 parent
a38997ad97
commit
9fea88c087
3 files changed
+45
-56
No files matched your search
@@ -9,7 +9,6 @@ const express = require('express')
|
||||
const graphqlHTTP = require('express-graphql')
|
||||
const schema = require('./schema/schema')
|
||||
const mongoose = require('mongoose')
|
||||
const mongodbConfig = require('./models/MongoDB')
|
||||
const checkJwt = require('./auth/middleware/jwt')
|
||||
|
||||
const cors = require('cors')
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
const jwt = require('express-jwt');
|
||||
const jwksRsa = require('jwks-rsa');
|
||||
const AUTH_CONFIG = require('../Auth0');
|
||||
const jwt = require('express-jwt')
|
||||
const jwksRsa = require('jwks-rsa')
|
||||
|
||||
// Authentication middleware. When used, the
|
||||
// if the access token exists, it be verified against
|
||||
// the Auth0 JSON Web Key Set
|
||||
@@ -12,14 +12,14 @@ const checkJwt = jwt({
|
||||
cache: true,
|
||||
rateLimit: true,
|
||||
jwksRequestsPerMinute: 1,
|
||||
jwksUri: `https://${AUTH_CONFIG.domain}/.well-known/jwks.json`
|
||||
jwksUri: `https://${process.env.AUTH0_DOMAIN}/.well-known/jwks.json`
|
||||
}),
|
||||
|
||||
// Validate the audience and the issuer.
|
||||
credentialsRequired: false,
|
||||
audience: AUTH_CONFIG.api_audience,
|
||||
issuer: AUTH_CONFIG.issuer,
|
||||
audience: process.env.AUTH0_AUDIENCE,
|
||||
issuer: process.env.AUTH0_ISSUER,
|
||||
algorithms: [`RS256`]
|
||||
});
|
||||
})
|
||||
|
||||
module.exports = checkJwt ;
|
||||
module.exports = checkJwt
|
||||
@@ -1,4 +1,4 @@
|
||||
const MODULE_NAME = "token-decoder";
|
||||
const MODULE_NAME = 'token-decoder'
|
||||
|
||||
/*
|
||||
JSON Web Token (JWT) is a compact, URL-safe means of representing
|
||||
@@ -10,82 +10,72 @@ const MODULE_NAME = "token-decoder";
|
||||
(MAC) and/or encrypted.
|
||||
*/
|
||||
|
||||
const JSONWebToken = require('jsonwebtoken'); // A library to deal with JSON Web Tokens.
|
||||
const webTokenLibrary = require('jwks-rsa'); // A library to retrieve RSA signing keys from a JWKS (JSON Web Key Set) endpoint.
|
||||
|
||||
const AUTH_CONFIG = require('./Auth0'); // Config where we have our secrets.
|
||||
const JSONWebToken = require('jsonwebtoken') // A library to deal with JSON Web Tokens.
|
||||
const webTokenLibrary = require('jwks-rsa') // A library to retrieve RSA signing keys from a JWKS (JSON Web Key Set) endpoint.
|
||||
|
||||
const decoder = webTokenLibrary({
|
||||
cache: true,
|
||||
rateLimit: true,
|
||||
jwksRequestsPerMinute: 1,
|
||||
jwksUri: `https://${AUTH_CONFIG.domain}/.well-known/jwks.json`
|
||||
jwksUri: `https://${process.env.AUTH0_DOMAIN}/.well-known/jwks.json`
|
||||
})
|
||||
|
||||
function decodeToken (token, callBackFunction) {
|
||||
try {
|
||||
if (global.INFO_LOG === true) { console.log('[INFO] ' + MODULE_NAME + ' -> decodeToken -> Entering function.') }
|
||||
|
||||
try{
|
||||
|
||||
if (global.INFO_LOG === true) { console.log("[INFO] " + MODULE_NAME + " -> decodeToken -> Entering function."); }
|
||||
|
||||
const decoded = JSONWebToken.decode(token, { complete: true });
|
||||
const header = decoded.header;
|
||||
const payload = decoded.payload;
|
||||
const decoded = JSONWebToken.decode(token, { complete: true })
|
||||
const header = decoded.header
|
||||
const payload = decoded.payload
|
||||
|
||||
if (
|
||||
header === null ||
|
||||
header.kid === null ||
|
||||
payload === null
|
||||
) {
|
||||
if (global.ERROR_LOG === true) { console.log ("[ERROR] " + MODULE_NAME + " -> decodeToken -> Invalid Token. "); }
|
||||
if (global.ERROR_LOG === true) { console.log ("[ERROR] " + MODULE_NAME + " -> decodeToken -> token = " + token); }
|
||||
callBackFunction(global.DEFAULT_FAIL_RESPONSE);
|
||||
return;
|
||||
if (global.ERROR_LOG === true) { console.log('[ERROR] ' + MODULE_NAME + ' -> decodeToken -> Invalid Token. ') }
|
||||
if (global.ERROR_LOG === true) { console.log('[ERROR] ' + MODULE_NAME + ' -> decodeToken -> token = ' + token) }
|
||||
callBackFunction(global.DEFAULT_FAIL_RESPONSE)
|
||||
return
|
||||
}
|
||||
|
||||
decoder.getSigningKey(header.kid, onKeyReady);
|
||||
decoder.getSigningKey(header.kid, onKeyReady)
|
||||
|
||||
function onKeyReady(err, key) {
|
||||
|
||||
if (global.INFO_LOG === true) { console.log("[INFO] " + MODULE_NAME + " -> decodeToken -> onKeyReady -> Entering function."); }
|
||||
function onKeyReady (err, key) {
|
||||
if (global.INFO_LOG === true) { console.log('[INFO] ' + MODULE_NAME + ' -> decodeToken -> onKeyReady -> Entering function.') }
|
||||
|
||||
if (err) {
|
||||
|
||||
if (global.ERROR_LOG === true) { console.log ("[ERROR] " + MODULE_NAME + " -> decodeToken -> onKeyReady -> Error getting the key. "); }
|
||||
if (global.ERROR_LOG === true) { console.log ("[ERROR] " + MODULE_NAME + " -> decodeToken -> onKeyReady -> key = " + key); }
|
||||
if (global.ERROR_LOG === true) { console.log ("[ERROR] " + MODULE_NAME + " -> decodeToken -> onKeyReady -> err = " + err); }
|
||||
callBackFunction(global.DEFAULT_FAIL_RESPONSE);
|
||||
return;
|
||||
if (global.ERROR_LOG === true) { console.log('[ERROR] ' + MODULE_NAME + ' -> decodeToken -> onKeyReady -> Error getting the key. ') }
|
||||
if (global.ERROR_LOG === true) { console.log('[ERROR] ' + MODULE_NAME + ' -> decodeToken -> onKeyReady -> key = ' + key) }
|
||||
if (global.ERROR_LOG === true) { console.log('[ERROR] ' + MODULE_NAME + ' -> decodeToken -> onKeyReady -> err = ' + err) }
|
||||
callBackFunction(global.DEFAULT_FAIL_RESPONSE)
|
||||
return
|
||||
}
|
||||
|
||||
JSONWebToken.verify(
|
||||
token,
|
||||
key.publicKey,
|
||||
{ algorithms: ['RS256'] },
|
||||
onVerified);
|
||||
onVerified)
|
||||
|
||||
function onVerified(err, decoded) {
|
||||
function onVerified (err, decoded) {
|
||||
if (global.INFO_LOG === true) { console.log('[INFO] ' + MODULE_NAME + ' -> decodeToken -> onKeyReady -> onVerified -> Entering function.') }
|
||||
|
||||
if (global.INFO_LOG === true) { console.log("[INFO] " + MODULE_NAME + " -> decodeToken -> onKeyReady -> onVerified -> Entering function."); }
|
||||
|
||||
if (err) {
|
||||
|
||||
if (global.ERROR_LOG === true) { console.log ("[ERROR] " + MODULE_NAME + " -> decodeToken -> onKeyReady -> onVerified -> Error verifying. "); }
|
||||
if (global.ERROR_LOG === true) { console.log ("[ERROR] " + MODULE_NAME + " -> decodeToken -> onKeyReady -> onVerified -> decoded = " + decoded); }
|
||||
if (global.ERROR_LOG === true) { console.log ("[ERROR] " + MODULE_NAME + " -> decodeToken -> onKeyReady -> onVerified -> err = " + err); }
|
||||
callBackFunction(global.DEFAULT_FAIL_RESPONSE);
|
||||
return;
|
||||
}
|
||||
|
||||
callBackFunction(global.DEFAULT_OK_RESPONSE, decoded);
|
||||
if (err) {
|
||||
if (global.ERROR_LOG === true) { console.log('[ERROR] ' + MODULE_NAME + ' -> decodeToken -> onKeyReady -> onVerified -> Error verifying. ') }
|
||||
if (global.ERROR_LOG === true) { console.log('[ERROR] ' + MODULE_NAME + ' -> decodeToken -> onKeyReady -> onVerified -> decoded = ' + decoded) }
|
||||
if (global.ERROR_LOG === true) { console.log('[ERROR] ' + MODULE_NAME + ' -> decodeToken -> onKeyReady -> onVerified -> err = ' + err) }
|
||||
callBackFunction(global.DEFAULT_FAIL_RESPONSE)
|
||||
return
|
||||
}
|
||||
|
||||
callBackFunction(global.DEFAULT_OK_RESPONSE, decoded)
|
||||
}
|
||||
}
|
||||
} catch(err) {
|
||||
|
||||
if (global.ERROR_LOG === true) { console.log("[ERROR] " + MODULE_NAME + " -> decodeToken -> err = " + err); }
|
||||
callBackFunction(global.DEFAULT_FAIL_RESPONSE);
|
||||
|
||||
} catch (err) {
|
||||
if (global.ERROR_LOG === true) { console.log('[ERROR] ' + MODULE_NAME + ' -> decodeToken -> err = ' + err) }
|
||||
callBackFunction(global.DEFAULT_FAIL_RESPONSE)
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = decodeToken;
|
||||
module.exports = decodeToken
|
||||
Reference in new issue
Block a user