Skip to content

Mount auth operations in main GQL schema#96

Merged
mcelicalderon merged 8 commits intomasterfrom
mount-auth-on-main-schema
Jun 12, 2020
Merged

Mount auth operations in main GQL schema#96
mcelicalderon merged 8 commits intomasterfrom
mount-auth-on-main-schema

Conversation

@mcelicalderon
Copy link
Copy Markdown
Member

@mcelicalderon mcelicalderon commented May 31, 2020

GQL specification is not very clear on how/where exactly authentication should be handled (here). After some reading and discussing with @00dav00 we have decided to implement this while still keeping a way to mount the schema in a separate route. This will allow to require/not_require authentication per field on the schema and having a default.

@mcelicalderon mcelicalderon added the enhancement New feature or request label May 31, 2020
@mcelicalderon mcelicalderon force-pushed the mount-auth-on-main-schema branch 2 times, most recently from a7de750 to d178626 Compare June 2, 2020 01:19
@mcelicalderon mcelicalderon mentioned this pull request Jun 7, 2020
@mcelicalderon mcelicalderon force-pushed the mount-auth-on-main-schema branch from d178626 to d8ea28d Compare June 7, 2020 22:47
@mcelicalderon mcelicalderon added the bug Something isn't working label Jun 8, 2020
@mcelicalderon mcelicalderon force-pushed the mount-auth-on-main-schema branch from 38f3685 to 510ac1e Compare June 8, 2020 02:03
@mcelicalderon mcelicalderon force-pushed the mount-auth-on-main-schema branch from 510ac1e to 2e63cda Compare June 8, 2020 02:22
@mcelicalderon mcelicalderon force-pushed the mount-auth-on-main-schema branch from 393db52 to 6898d21 Compare June 9, 2020 03:39
Comment thread lib/graphql_devise/mutations/sign_up.rb Outdated
{ authenticatable: resource }
else
clean_up_passwords(resource)
resource.clean_up_passwords if resource.respond_to?(:clean_up_passwords)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since rails is a dependency, did you considered try ?

Comment thread lib/graphql_devise/schema_plugin.rb Outdated
field = traced_field(trace_data)
provided_value = authenticate_option(field, trace_data)

if (!provided_value.nil? && provided_value) || @authenticate_default
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What about

provided_value.presence

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

provided_value might be false so I cannot use presence. But now I see this won't skip authentication if the provided value in the field is false and the default is true. I'll fix it.

Copy link
Copy Markdown
Contributor

@00dav00 00dav00 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💯

@mcelicalderon mcelicalderon marked this pull request as ready for review June 10, 2020 03:30
Comment thread README.md Outdated
option is provided, the route will be `/graphql_auth`. This has no effect on your own application schema.
More on this in the next section.
### Important
Remember this gem mounts a completely separate GraphQL schema on a separate controller in the route
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What about Remember that by default....

Comment thread README.md
before_action -> { set_resource_by_token(:user) }

def my_action
render json: DummySchema.execute(params[:query], context: graphql_context)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is graphql_context supposed to be set by the main project?
In that case I think it may be useful to add a comment or something like

     graphql_context = the_gql_context_created_by_your_application
     render json: DummySchema.execute(params[:query], context: graphql_context) 

In that way it is clear that graphql_context is not provided by the egm and shouldn't be copypasta

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no, this is a method in our concern

Comment thread README.md Outdated
provided by the `at` option in the `mount_graphql_devise_for` method in the `config/routes.rb` file by default. If no `at`
option is provided, the route will be `/graphql_auth`.

**Starting with `v0.12.0`** you can opt-in to a new behavior where you actually load this gem's
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
**Starting with `v0.12.0`** you can opt-in to a new behavior where you actually load this gem's
**Starting with `v0.12.0`** you can opt-in to load this auth queries and mutations into into your own application's schema.

Comment thread README.md
1. `query`: This param is mandatory unless you skip all queries via the resource loader
options. This should be the same `QueryType` you provide to the `query` method
in your schema.
1. `mutation`: This param mandatory unless you skip all mutations via the resource loader
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
1. `mutation`: This param mandatory unless you skip all mutations via the resource loader
1. `mutation`: This param is mandatory unless you skip all mutations via the resource loader

SetUserByToken.module_eval do
attr_accessor :client_id, :token, :resource

alias_method :set_resource_by_token, :set_user_by_token
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💯

@mcelicalderon mcelicalderon force-pushed the mount-auth-on-main-schema branch from 3a12f80 to 687ebaf Compare June 11, 2020 23:07
@mcelicalderon mcelicalderon merged commit a0cd5a3 into master Jun 12, 2020
@mcelicalderon mcelicalderon deleted the mount-auth-on-main-schema branch June 12, 2020 00:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Separate endpoint for graphql auth mandatory

2 participants