Merge pull request #17 from nikolabjelo/master

quick fix for JWT expiration date
This commit is contained in:
Barry Low authored and GitHub committed 2018-10-23 01:06:26 -07:00
commit e776beabd3
5 files changed
+1561 -1049

No files matched your search

+4 -1
View File
@@ -19,7 +19,10 @@ const authRetryLink = onError(
if (graphQLErrors) {
// User access token has expired
// console.log('authLink: ', graphQLErrors) // check for error message to intercept and resend with Auth0 access token
if (graphQLErrors[0].message === 'Not logged in') {
if (graphQLErrors[0].message === 'Context creation failed: jwt expired') {
window.localStorage.clear()
location.reload()
} else if (graphQLErrors[0].message === 'Not logged in') {
// We assume we have auth0 access token needed to run the async request
// Let's refresh token through async request
return new Observable(observer => {
+4
View File
@@ -2,3 +2,7 @@ GRAPHQL_API_URL=https://app-api.advancedalgos.net/graphql
TEAMS_API_URL=https://teams-api.advancedalgos.net/graphql
USERS_API_URL=https://users-api.advancedalgos.net/graphql
KEYVAULT_API_URL=https://keyvault-api.advancedalgos.net/graphql
AUTH0_DOMAIN=auth0-domain
AUTH0_AUDIENCE=auth0-audience
AUTH0_ISSUER=auth0-issuer
+1512 -1042
View File
File diff suppressed because it is too large. Load diff
+2
View File
@@ -31,8 +31,10 @@
"cors": "^2.8.4",
"dotenv": "^6.1.0",
"express": "^4.16.3",
"express-jwt": "^5.3.1",
"graphql": "^14.0.2",
"graphql-tools": "^4.0.0",
"jwks-rsa": "^1.3.0",
"node-fetch": "^2.2.0",
"winston": "^3.1.0"
}
+39 -6
View File
@@ -1,8 +1,11 @@
import express from 'express'
import cors from 'cors'
import 'dotenv/config'
import { ApolloServer } from 'apollo-server-express'
import { ApolloServer, ForbiddenError } from 'apollo-server-express'
import { mergeSchemas } from 'graphql-tools'
import jwt from 'express-jwt'
import jwksRsa from 'jwks-rsa'
import { createTransformedRemoteSchema } from './createRemoteSchema'
import { teams } from './links'
import logger from './logger'
@@ -44,20 +47,50 @@ async function run () {
}
}
`
const app = express()
app.use('/graphql',
jwt({
secret: jwksRsa.expressJwtSecret({
cache: true,
rateLimit: true,
jwksRequestsPerMinute: 1,
jwksUri: `https://${process.env.AUTH0_DOMAIN}/.well-known/jwks.json`
}),
credentialsRequired: false,
audience: process.env.AUTH0_AUDIENCE,
issuer: process.env.AUTH0_ISSUER,
algorithms: [`RS256`]
}),
function (err, req, res, next) {
if (err.code === 'invalid_token') {
res.error = err.message
}
return next()
}
)
const context = ({ req, res }) => {
if (res.error) {
throw new ForbiddenError(res.error)
}
return req
}
const server = new ApolloServer({
schema,
context: ({ req }) => req, // placeholder until specific use case for context on Master App server
context,
formatError: error => {
logger.error('Error on Apolo Server: ', error)
return error;
return error
},
formatResponse: response => {
logger.info('Response from Apolo Server: ', response)
return response;
return response
},
playground: {
settings: { 'editor.theme': 'light' },
settings: { 'editor.theme': 'dark' },
tabs: [
{
endpoint: process.env.GRAPHQL_API_URL,
@@ -67,7 +100,7 @@ async function run () {
}
})
server.applyMiddleware({ app });
server.applyMiddleware({ app })
app.use(cors())