Add token verification with development basic header
This commit is contained in:
+11
-2
@@ -1,7 +1,7 @@
|
||||
import dotenv from 'dotenv';
|
||||
dotenv.config();
|
||||
|
||||
import { ApolloServer } from 'apollo-server';
|
||||
import { ApolloServer, AuthenticationError } from 'apollo-server';
|
||||
import knexStringcase from 'knex-stringcase';
|
||||
import { dbConfig } from './config';
|
||||
import { typeDefs } from './schema';
|
||||
@@ -10,6 +10,7 @@ import { OrderAPI } from './datasources/order-api';
|
||||
import { ProductAPI } from './datasources/product-api';
|
||||
import { DesignerAPI } from './datasources/designer-api';
|
||||
import { Api2DataSource } from './datasources/api2-datasource';
|
||||
import { verifyToken } from './cognito/cognito-client';
|
||||
|
||||
console.log(`dbConfig`, dbConfig);
|
||||
|
||||
@@ -27,7 +28,15 @@ const dataSources = () => ({
|
||||
});
|
||||
|
||||
const context = async ({ req }) => {
|
||||
return { data: { foo: 'bar' } };
|
||||
const authHeader = req.headers.authorization || '';
|
||||
if (authHeader.startsWith('Bearer ')) {
|
||||
const token = authHeader.substring(7, authHeader.length);
|
||||
const res = await verifyToken({ token });
|
||||
return { auth: res };
|
||||
} else if (authHeader == 'Basic ZGV2OmRldg==') {
|
||||
return { auth: 'during development' };
|
||||
}
|
||||
throw new AuthenticationError('Not authorized');
|
||||
};
|
||||
|
||||
async function main() {
|
||||
|
||||
Reference in New Issue
Block a user