Skip to content
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

Mount auth operations in main GQL schema #96

Merged
merged 8 commits into from
Jun 12, 2020

Conversation

mcelicalderon
Copy link
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 added the bug Something isn't working label Jun 8, 2020
@@ -35,7 +35,7 @@ def resolve(confirm_success_url: nil, **attrs)

{ authenticatable: resource }
else
clean_up_passwords(resource)
resource.clean_up_passwords if resource.respond_to?(:clean_up_passwords)
Copy link
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 ?

field = traced_field(trace_data)
provided_value = authenticate_option(field, trace_data)

if (!provided_value.nil? && provided_value) || @authenticate_default
Copy link
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
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
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
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
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....

before_action -> { set_resource_by_token(:user) }

def my_action
render json: DummySchema.execute(params[:query], context: graphql_context)
Copy link
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
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

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
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.

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
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
Contributor

Choose a reason for hiding this comment

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

💯

@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