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

Commit

Permalink
Add additional scope without space and lowercase
Browse files Browse the repository at this point in the history
Better aligns with conventions and standards for adding scopes
to the hasScope schema directive for authorization.
  • Loading branch information
johnymontana committed Sep 7, 2020
1 parent 98819f0 commit 34125ba
Show file tree
Hide file tree
Showing 4 changed files with 1,009 additions and 187 deletions.
47 changes: 47 additions & 0 deletions example/apollo-server/authScopes.js
@@ -0,0 +1,47 @@
import { makeAugmentedSchema } from '../../src/index';
import { ApolloServer } from 'apollo-server';
import neo4j from 'neo4j-driver';

// JWT
// eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwiaWF0IjoxNTE2MjM5MDIyLCJzY29wZXMiOlsicmVhZDp1c2VyIiwiY3JlYXRlOnVzZXIiXX0.jCidMhYKk_0s8aQpXojYwZYz00eIG9lD_DbeXRKj4vA

// scopes
// "scopes": ["read:user", "create:user"]

// JWT_SECRET
// oqldBPU1yMXcrTwcha1a9PGi9RHlPVzQ

const typeDefs = `
type User {
userId: ID!
name: String
}
type Business {
name: String
}
`;

const schema = makeAugmentedSchema({
typeDefs,
config: { auth: { hasScope: true } }
});

const driver = neo4j.driver(
'bolt://localhost:7687',
neo4j.auth.basic('neo4j', 'letmein')
);

const server = new ApolloServer({
schema,
context: ({ req }) => {
return {
req,
driver
};
}
});

server.listen().then(({ url }) => {
console.log(`GraphQL API ready at ${url}`);
});
1 change: 1 addition & 0 deletions package.json
Expand Up @@ -11,6 +11,7 @@
"start-interface": "DEBUG=neo4j-graphql.js nodemon ./example/apollo-server/interface-union-example.js --exec babel-node -e js",
"start-gateway": "nodemon ./example/apollo-federation/gateway.js --exec babel-node -e js",
"start-bookmark-example": "nodemon ./example/apollo-server/bookmarks.js --exec babel-node -e js",
"start-auth-example": "JWT_SECRET=oqldBPU1yMXcrTwcha1a9PGi9RHlPVzQ nodemon ./example/apollo-server/authScopes.js --exec babel-node -e js",
"build": "babel src --presets @babel/preset-env --out-dir dist",
"build-with-sourcemaps": "babel src --presets @babel/preset-env --out-dir dist --source-maps",
"precommit": "lint-staged",
Expand Down
14 changes: 10 additions & 4 deletions src/augment/directives.js
Expand Up @@ -251,10 +251,16 @@ export const buildAuthScopeDirective = ({ scopes = [] }) =>
name: buildName({ name: 'scopes' }),
value: {
kind: Kind.LIST,
values: scopes.map(scope => ({
kind: Kind.STRING,
value: `${scope.typeName}: ${scope.mutation}`
}))
values: scopes.flatMap(scope => [
{
kind: Kind.STRING,
value: `${scope.typeName}: ${scope.mutation}`
},
{
kind: Kind.STRING,
value: `${scope.mutation}:${scope.typeName}`.toLowerCase()
}
])
}
})
]
Expand Down

0 comments on commit 34125ba

Please sign in to comment.