Skip to content
This repository was archived by the owner on Sep 3, 2021. It is now read-only.

Commit 34125ba

Browse files
committedSep 7, 2020
Add additional scope without space and lowercase
Better aligns with conventions and standards for adding scopes to the hasScope schema directive for authorization.
1 parent 98819f0 commit 34125ba

File tree

4 files changed

+1009
-187
lines changed

4 files changed

+1009
-187
lines changed
 

‎example/apollo-server/authScopes.js

+47
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
import { makeAugmentedSchema } from '../../src/index';
2+
import { ApolloServer } from 'apollo-server';
3+
import neo4j from 'neo4j-driver';
4+
5+
// JWT
6+
// eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwiaWF0IjoxNTE2MjM5MDIyLCJzY29wZXMiOlsicmVhZDp1c2VyIiwiY3JlYXRlOnVzZXIiXX0.jCidMhYKk_0s8aQpXojYwZYz00eIG9lD_DbeXRKj4vA
7+
8+
// scopes
9+
// "scopes": ["read:user", "create:user"]
10+
11+
// JWT_SECRET
12+
// oqldBPU1yMXcrTwcha1a9PGi9RHlPVzQ
13+
14+
const typeDefs = `
15+
type User {
16+
userId: ID!
17+
name: String
18+
}
19+
20+
type Business {
21+
name: String
22+
}
23+
`;
24+
25+
const schema = makeAugmentedSchema({
26+
typeDefs,
27+
config: { auth: { hasScope: true } }
28+
});
29+
30+
const driver = neo4j.driver(
31+
'bolt://localhost:7687',
32+
neo4j.auth.basic('neo4j', 'letmein')
33+
);
34+
35+
const server = new ApolloServer({
36+
schema,
37+
context: ({ req }) => {
38+
return {
39+
req,
40+
driver
41+
};
42+
}
43+
});
44+
45+
server.listen().then(({ url }) => {
46+
console.log(`GraphQL API ready at ${url}`);
47+
});

‎package.json

+1
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
"start-interface": "DEBUG=neo4j-graphql.js nodemon ./example/apollo-server/interface-union-example.js --exec babel-node -e js",
1212
"start-gateway": "nodemon ./example/apollo-federation/gateway.js --exec babel-node -e js",
1313
"start-bookmark-example": "nodemon ./example/apollo-server/bookmarks.js --exec babel-node -e js",
14+
"start-auth-example": "JWT_SECRET=oqldBPU1yMXcrTwcha1a9PGi9RHlPVzQ nodemon ./example/apollo-server/authScopes.js --exec babel-node -e js",
1415
"build": "babel src --presets @babel/preset-env --out-dir dist",
1516
"build-with-sourcemaps": "babel src --presets @babel/preset-env --out-dir dist --source-maps",
1617
"precommit": "lint-staged",

‎src/augment/directives.js

+10-4
Original file line numberDiff line numberDiff line change
@@ -251,10 +251,16 @@ export const buildAuthScopeDirective = ({ scopes = [] }) =>
251251
name: buildName({ name: 'scopes' }),
252252
value: {
253253
kind: Kind.LIST,
254-
values: scopes.map(scope => ({
255-
kind: Kind.STRING,
256-
value: `${scope.typeName}: ${scope.mutation}`
257-
}))
254+
values: scopes.flatMap(scope => [
255+
{
256+
kind: Kind.STRING,
257+
value: `${scope.typeName}: ${scope.mutation}`
258+
},
259+
{
260+
kind: Kind.STRING,
261+
value: `${scope.mutation}:${scope.typeName}`.toLowerCase()
262+
}
263+
])
258264
}
259265
})
260266
]

0 commit comments

Comments
 (0)