mirror of
https://github.com/vale981/Vulcan
synced 2025-03-06 01:51:40 -05:00
Add apiKey support
This commit is contained in:
parent
9d27f386c9
commit
01cbfe32b7
1 changed files with 9 additions and 2 deletions
|
@ -19,6 +19,7 @@ import {GraphQLSchema} from '../../modules/graphql.js';
|
||||||
import _merge from 'lodash/merge';
|
import _merge from 'lodash/merge';
|
||||||
import {getUser} from 'meteor/apollo';
|
import {getUser} from 'meteor/apollo';
|
||||||
import {getHeaderLocale} from '../intl.js';
|
import {getHeaderLocale} from '../intl.js';
|
||||||
|
import {getSetting} from '../../modules/settings.js';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Called once on server creation
|
* Called once on server creation
|
||||||
|
@ -105,6 +106,7 @@ export const computeContextFromReq = (currentContext, customContextFromReq) => {
|
||||||
|
|
||||||
// create options given the current request
|
// create options given the current request
|
||||||
const handleReq = async req => {
|
const handleReq = async req => {
|
||||||
|
const { headers } = req;
|
||||||
let context;
|
let context;
|
||||||
let user = null;
|
let user = null;
|
||||||
|
|
||||||
|
@ -119,12 +121,17 @@ export const computeContextFromReq = (currentContext, customContextFromReq) => {
|
||||||
await setupAuthToken(context, req);
|
await setupAuthToken(context, req);
|
||||||
|
|
||||||
//add the headers to the context
|
//add the headers to the context
|
||||||
context.headers = req.headers;
|
context.headers = headers;
|
||||||
|
|
||||||
// console.log('// apollo_server.js user-agent:', req.headers['user-agent']);
|
// console.log('// apollo_server.js user-agent:', req.headers['user-agent']);
|
||||||
// console.log('// apollo_server.js locale:', req.headers.locale);
|
// console.log('// apollo_server.js locale:', req.headers.locale);
|
||||||
|
|
||||||
context.locale = getHeaderLocale(req.headers, context.currentUser && context.currentUser.locale);
|
// if apiKey is present, assign "fake" currentUser with admin rights
|
||||||
|
if (headers.apikey && (headers.apikey === getSetting('vulcan.apiKey'))) {
|
||||||
|
context.currentUser = { isAdmin: true, isApiUser: true };
|
||||||
|
}
|
||||||
|
|
||||||
|
context.locale = getHeaderLocale(headers, context.currentUser && context.currentUser.locale);
|
||||||
|
|
||||||
return context;
|
return context;
|
||||||
};
|
};
|
||||||
|
|
Loading…
Add table
Reference in a new issue