graphql

fabrao 2020-05-28T02:48:22.111100Z

hello all, how do you deal with authentication ?

fabrao 2020-05-28T02:50:06.112400Z

I thought using a mutation login that after check user and password return a token that will pass in all queries. Is that a good way to do this?

defa 2020-05-28T07:19:55.114600Z

I use https://www.keycloak.org as an external OAuth 2 provider and have an interceptor attached to verify this token. Works fine.

defa 2020-05-28T07:21:22.115Z

… now I’m trying to use GraphQL directives implement role based access controls on resolvers and I’m struggling with finding the right place to put my interceptor…

fabrao 2020-05-28T13:22:35.119400Z

Lennart have you used lacinia?

2020-05-28T17:44:57.120500Z

Yes

2020-05-28T19:15:18.120800Z

We basically have a little interceptor in our stack that checks you have a valid access token (JWT in our case). So thats prior to lacinia getting involved.

2020-05-28T19:19:52.121100Z

And our clients send it with the Authorization HTTP header using the Bearer schema

2020-05-28T05:08:54.114200Z

We just pass an Authentication header, with a JWT that you got from an oauth provider

2020-05-28T06:52:16.114400Z

You can pass a connection-init-payload with Apollo or re-graph, and lacinia-pedestal can handle it

defa 2020-05-28T07:26:12.118800Z

Regarding https://lacinia.readthedocs.io/en/latest/directives.html… I use JWT for login/access control and in the token’s claims there are the roles assigned to the user. I used GraphQL directives to attach roles to queries and mutations and I’d like to check them before executing the resolver. Within the resolver I can access the directive defined in the schema:

(->> context
     :com.walmartlabs.lacinia/selection
     :field-definition
     :directives
     (filter #(= :access (:directive-type %)))
     first
     :directive-args
     :roles)
In the schema the directive is defined like this:
:directives [{:directive-type :access
              :directive-args {:roles ["admin"]}
and I can check against the claims I’m extracting from the JWT token using a custom interceptor. Now I’m struggling to find the right place to inject an interceptor that checks the roles from the JWT token claims against the access-roles defined in the schema (query directive). The thing is, that he context in none of the places I tried to inject my interceptor has the :com.walmartlabs.lacinia/selection key. Any ideas? … after digging around and thinking a little, I guess I’ll go with wrapping all resolvers before passing them to com.walmartlabs.lacinia.util/attach-resolvers . Any better ideas?

hlship 2020-05-28T16:23:46.120Z

Feels like this needs a Lacinia enhancement; selections-seq2 could expose field-level directives.