-
Notifications
You must be signed in to change notification settings - Fork 135
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: Optionally add permissions to gql resolvers #119
feat: Optionally add permissions to gql resolvers #119
Conversation
d4a97a5
to
8ed73c0
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good overall. Needs some changes
20a2591
to
009c637
Compare
@simonas-notcat updated |
|
||
if (input?.order) { | ||
for (const item of input.order) { | ||
qb = qb.orderBy(`${escape(tablename)}.${escape(item.column)}`, item.direction) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No need to use another package for that. You can do the same thing with:
qb = qb.orderBy(`${qb.connection.driver.escape(tablename)}.${qb.connection.driver.escape(item.column)}`, item.direction)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
oh cool, i looked for this, guess I missed it.
@@ -21,6 +24,7 @@ import { Identity } from '../entities/identity' | |||
|
|||
export interface Context { | |||
agent: Agent | |||
authenticatedDid?: Promise<string> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why is this Promise<string>
and not just a simple string
?
I was thinking, that it can be used like that:
const server = new ApolloServer({
typeDefs: [Daf.Gql.baseTypeDefs, Daf.Gql.Core.typeDefs],
resolvers: merge(Daf.Gql.Core.resolvers),
context: async ({ req }) => {
const authenticatedDid = await applicationSpecificLogic(req.headers.authorization)
return { agent, authenticatedDid }
}
})
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the context function can't be async. Because verifying a jwt is an async function, this has to be a promise.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Your mentioned issue is almost 4 years old. I just tried it and it works fine:
https://github.com/uport-project/daf/blob/master/examples/id-hub/src/index.ts#L50
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It was causing linting warning in my ide when I tried before, now its not, must have been something wrong with my config. My mistake, will change.
packages/daf-core/src/agent.ts
Outdated
@@ -9,6 +9,7 @@ import { ActionHandler } from './action/action-handler' | |||
import { Action } from './types' | |||
import { Message, MetaData } from './entities/message' | |||
import { Connection } from 'typeorm' | |||
import { verifyJWT } from 'did-jwt' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove this
packages/daf-core/src/agent.ts
Outdated
@@ -34,6 +35,7 @@ interface Config { | |||
|
|||
export class Agent extends EventEmitter { | |||
readonly dbConnection: Promise<Connection> | |||
readonly authentication?: boolean |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove this
if (ctx.authenticatedDid) { | ||
const authIdent = await ctx.authenticatedDid | ||
qb = qb.andWhere( | ||
new Brackets(qb => { | ||
qb.where('message.to = :ident', { ident: authIdent }).orWhere('message.from = :ident', { | ||
ident: authIdent, | ||
}) | ||
}), | ||
) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If we change authenticatedDid
to string
then this can be simplified like that:
if (ctx.authenticatedDid) {
qb = qb.andWhere(
new Brackets(qb => {
qb.where('message.to = :ident', { ident: ctx.authenticatedDid })
.orWhere('message.from = :ident', { ident: ctx.authenticatedDid})
}),
)
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@walfly I just released
Sorry for inconvenience |
009c637
to
6afdc81
Compare
6afdc81
to
0d5b212
Compare
@simonas-notcat alright ready now |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great work! Thank you
Still need to add more tests. Allows configuring agent with authentication boolean at instantiation. An auth-identity can be set in the request context and resolvers will include that identity in their generated queries if authentication is set to true.