graphql_devise 0.13.0 → 0.13.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +13 -0
- data/README.md +76 -65
- data/lib/generators/graphql_devise/install_generator.rb +1 -1
- data/lib/graphql_devise/mutations/sign_up.rb +9 -2
- data/lib/graphql_devise/version.rb +1 -1
- data/spec/generators/graphql_devise/install_generator_spec.rb +1 -1
- data/spec/requests/mutations/sign_up_spec.rb +13 -2
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 543ed51aaeb46699f17efb47cb13909ebfcd98ee0b97d27207fa0423199d72d2
|
4
|
+
data.tar.gz: 393496018363cadce3251a7ac4b3b9b0c74f8830fd72414fd97d47453406df2a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c085a18386d7d2ae725140a1c4a089cebcae117485395145dbc24106fc28a97a6d35b895bb3ae990243c936ed3253467d0a471b85bda3180844421ea85f3a3a0
|
7
|
+
data.tar.gz: c8a271975c6306edbac33bacace9c00db6286eb988f015cec36007be0d860f6f92b3b9b8c65d5d7b4f5d2f524c8a306815b7a9b56141b759ef53ccfbc8c9d526
|
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,18 @@
|
|
1
1
|
# Changelog
|
2
2
|
|
3
|
+
## [v0.13.1](https://github.com/graphql-devise/graphql_devise/tree/v0.13.1) (2020-07-29)
|
4
|
+
|
5
|
+
[Full Changelog](https://github.com/graphql-devise/graphql_devise/compare/v0.13.0...v0.13.1)
|
6
|
+
|
7
|
+
**Implemented enhancements:**
|
8
|
+
|
9
|
+
- Add credentials field on signUp mutation [\#122](https://github.com/graphql-devise/graphql_devise/pull/122) ([mcelicalderon](https://github.com/mcelicalderon))
|
10
|
+
|
11
|
+
**Closed issues:**
|
12
|
+
|
13
|
+
- Checking for `performed?` when mounting into your graphql schema. [\#110](https://github.com/graphql-devise/graphql_devise/issues/110)
|
14
|
+
- no query string for email reset [\#104](https://github.com/graphql-devise/graphql_devise/issues/104)
|
15
|
+
|
3
16
|
## [v0.13.0](https://github.com/graphql-devise/graphql_devise/tree/v0.13.0) (2020-06-22)
|
4
17
|
|
5
18
|
[Full Changelog](https://github.com/graphql-devise/graphql_devise/compare/v0.12.3...v0.13.0)
|
data/README.md
CHANGED
@@ -14,19 +14,22 @@ GraphQL interface on top of the [Devise Token Auth](https://github.com/lynndylan
|
|
14
14
|
* [Installation](#installation)
|
15
15
|
* [Running the Generator](#running-the-generator)
|
16
16
|
* [Mounting the Schema in a Separate Route](#mounting-the-schema-in-a-separate-route)
|
17
|
-
|
18
|
-
|
17
|
+
* [Important](#important)
|
18
|
+
* [Mounting Operations in Your Own Schema (> v0.12.0)](#mounting-operations-in-your-own-schema--v0120)
|
19
|
+
* [Important](#important-1)
|
19
20
|
* [Usage](#usage)
|
20
21
|
* [Mounting Auth Schema on a Separate Route](#mounting-auth-schema-on-a-separate-route)
|
21
22
|
* [Mounting Operations Into Your Own Schema](#mounting-operations-into-your-own-schema)
|
22
23
|
* [Available Mount Options](#available-mount-options)
|
23
24
|
* [Available Operations](#available-operations)
|
24
25
|
* [Configuring Model](#configuring-model)
|
26
|
+
* [Email Reconfirmation](#email-reconfirmation)
|
25
27
|
* [Customizing Email Templates](#customizing-email-templates)
|
26
28
|
* [I18n](#i18n)
|
27
29
|
* [Authenticating Controller Actions](#authenticating-controller-actions)
|
28
30
|
* [Authenticate Before Reaching Your GQL Schema](#authenticate-before-reaching-your-gql-schema)
|
29
31
|
* [Authenticate in Your GQL Schema](#authenticate-in-your-gql-schema)
|
32
|
+
* [Important](#important-2)
|
30
33
|
* [Making Requests](#making-requests)
|
31
34
|
* [Mutations](#mutations)
|
32
35
|
* [Queries](#queries)
|
@@ -39,20 +42,19 @@ GraphQL interface on top of the [Devise Token Auth](https://github.com/lynndylan
|
|
39
42
|
* [Contributing](#contributing)
|
40
43
|
* [License](#license)
|
41
44
|
|
42
|
-
<!-- Added by:
|
45
|
+
<!-- Added by: david, at: mar jul 14 08:08:02 -05 2020 -->
|
43
46
|
|
44
47
|
<!--te-->
|
45
48
|
|
46
49
|
## Introduction
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
still controlled by DTA. For that reason
|
52
|
-
|
53
|
-
[
|
54
|
-
|
55
|
-
in order to use this gem to its full potential**.
|
50
|
+
Graphql-Devise heavily relies on two gems:
|
51
|
+
- [Devise Token Auth](https://github.com/lynndylanhurley/devise_token_auth) (DTA)
|
52
|
+
- [Devise](https://github.com/heartcombo/devise) (which is a DTA dependency)
|
53
|
+
|
54
|
+
This gem provides a GraphQL interface on top of DTA which is designed for REST APIs. Features like token management, token expiration and everything up until using the actual GraphQL schema is still controlled by DTA. For that reason the gem's generator invokes DTA and Devise generators and creates initializer files for each one of them.
|
55
|
+
|
56
|
+
**We strongly recommend getting familiar with [DTA documentation](https://github.com/lynndylanhurley/devise_token_auth) to use this gem to its full potential**.
|
57
|
+
More configuration details available in [configuration section](#more-configuration-options)
|
56
58
|
|
57
59
|
## Installation
|
58
60
|
|
@@ -68,20 +70,21 @@ $ bundle
|
|
68
70
|
```
|
69
71
|
|
70
72
|
### Running the Generator
|
71
|
-
Graphql Devise generator will execute `Devise` and `Devise Token Auth`
|
72
|
-
generators for you. These will make the required changes for the gems to
|
73
|
-
work correctly. All configurations for [Devise](https://github.com/plataformatec/devise) and
|
74
|
-
[Devise Token Auth](https://github.com/lynndylanhurley/devise_token_auth) are available,
|
75
|
-
so you can read the docs there to customize your options.
|
76
|
-
Configurations are done via initializer files as usual, one per gem.
|
73
|
+
Graphql Devise generator will execute `Devise` and `Devise Token Auth` generators to setup the gems in your project. You can customize them to your needs using their initializer files(one per gem) as usual.
|
77
74
|
|
78
|
-
#### Mounting the Schema in a Separate Route
|
79
75
|
```bash
|
80
76
|
$ bundle exec rails generate graphql_devise:install
|
81
77
|
```
|
78
|
+
The generator accepts 2 params:
|
79
|
+
- `user_class`: Model name in which `Devise` modules will be included. This uses a `find or create` strategy. Defaults to `User`.
|
80
|
+
- `mount_path`: Path in which the dedicated graphql schema for devise will be mounted. Defaults to `/graphql_auth`.
|
82
81
|
|
83
|
-
The
|
84
|
-
|
82
|
+
The option `mount` is available starting from `v0.12.0`. This option will allow you to mount the operations in your own schema instead of a dedicated one. When this option is provided `mount_path` param is not used.
|
83
|
+
|
84
|
+
#### Mounting the Schema in a Separate Route
|
85
|
+
|
86
|
+
To configure the gem to use a separate schema, the generator will use `user_class` and `mount_path` params.
|
87
|
+
The route will be mounted in `config/routes.rb`. For instance the executing:
|
85
88
|
|
86
89
|
```bash
|
87
90
|
$ bundle exec rails g graphql_devise:install Admin api/auth
|
@@ -99,32 +102,43 @@ Will do the following:
|
|
99
102
|
`Admin` could be any model name you are going to be using for authentication,
|
100
103
|
and `api/auth` could be any mount path you would like to use for auth.
|
101
104
|
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
105
|
+
##### Important
|
106
|
+
- Remember that by default this gem mounts a completely separate GraphQL schema on a separate controller in the route provided by the `at` option in the `mount_graphql_devise_for` method in the `config/routes.rb` file. If no `at` option is provided, the route will be `/graphql_auth`.
|
107
|
+
- Avoid passing the `--mount` option or the gem will try to use an existing schema.
|
108
|
+
|
109
|
+
#### Mounting Operations in Your Own Schema (> v0.12.0)
|
110
|
+
To configure the gem to use your own GQL schema use the `--mount` option.
|
111
|
+
For instance the executing:
|
106
112
|
|
107
113
|
```bash
|
108
114
|
$ bundle exec rails g graphql_devise:install Admin --mount MySchema
|
109
115
|
```
|
110
116
|
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
117
|
+
Will do the following:
|
118
|
+
- Execute `Devise` install generator
|
119
|
+
- Execute `Devise Token Auth` install generator with `Admin` and `api/auth` as params
|
120
|
+
- Find or create `Admin` model
|
121
|
+
- Add `devise` modules to `Admin` model
|
122
|
+
- Other changes that you can find [here](https://devise-token-auth.gitbook.io/devise-token-auth/config)
|
123
|
+
- Add `SchemaPlugin` to the specified schema.
|
115
124
|
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
125
|
+
|
126
|
+
##### Important
|
127
|
+
- When using the `--mount` option the `mount_path` params is ignored.
|
128
|
+
- The generator will look for your schema under `app/graphql/` directory. We are expecting the name of the file is the same as the as the one passed in the mount option transformed with `underscore`. In the example, passing `MySchema`, will try to find the file `app/graphql/my_schema.rb`.
|
129
|
+
- You can actually mount a resource's auth schema in a separate route and in your app's schema at the same time, but that's probably not a common scenario.
|
120
130
|
|
121
131
|
## Usage
|
122
|
-
### Mounting Auth Schema on a Separate Route
|
123
|
-
The generator can do this step for you by default. Remember now you can mount this gem's
|
124
|
-
auth operations into your own schema as described in [this section](#mounting-operations-into-your-own-schema).
|
125
132
|
|
133
|
+
GraphqlDevise operations can be used in two ways:
|
134
|
+
- Using a [separate schema](#mounting-auth-schema-on-a-separate-route) via `mount_graphql_devise_for` helper in the routes file.
|
135
|
+
- Using [your own schema](#mounting-operations-into-your-own-schema) by adding a plugin in the class.
|
136
|
+
|
137
|
+
|
138
|
+
Creating a separate schema is the default option, the generator will do that by default.
|
139
|
+
|
140
|
+
### Mounting Auth Schema on a Separate Route
|
126
141
|
|
127
|
-
Routes can be added using the generator or manually.
|
128
142
|
You can mount this gem's GraphQL auth schema in your routes file like this:
|
129
143
|
|
130
144
|
```ruby
|
@@ -150,11 +164,13 @@ Rails.application.routes.draw do
|
|
150
164
|
)
|
151
165
|
end
|
152
166
|
```
|
167
|
+
This can be done using the generator or manually.
|
153
168
|
The second argument of the `mount_graphql_devise` method is a hash of options where you can
|
154
169
|
customize how the queries and mutations are mounted into the schema. For a list of available
|
155
170
|
options go [here](#available-mount-options)
|
156
171
|
|
157
172
|
### Mounting Operations Into Your Own Schema
|
173
|
+
|
158
174
|
Starting with `v0.12.0` you can now mount the GQL operations provided by this gem into your
|
159
175
|
app's main schema.
|
160
176
|
|
@@ -354,11 +370,10 @@ GraphQL Devise supports locales. For example, the `graphql_devise.confirmations.
|
|
354
370
|
Keep in mind that if your app uses multiple locales, you should set the `I18n.locale` accordingly. You can learn how to do this [here](https://guides.rubyonrails.org/i18n.html).
|
355
371
|
|
356
372
|
### Authenticating Controller Actions
|
357
|
-
|
358
|
-
For this you have two alternatives.
|
373
|
+
When mounting the operation is in you own schema instead of a dedicated one, you will need to authenticate users in your controllers, just like in DTA. There are 2 alternatives to accomplish this.
|
359
374
|
|
360
375
|
#### Authenticate Before Reaching Your GQL Schema
|
361
|
-
For this you need to call `authenticate_<model>!` in a before_action hook
|
376
|
+
For this you will need to call `authenticate_<model>!` in a `before_action` controller hook.
|
362
377
|
In our example our model is `User`, so it would look like this:
|
363
378
|
```ruby
|
364
379
|
# app/controllers/my_controller.rb
|
@@ -369,15 +384,14 @@ class MyController < ApplicationController
|
|
369
384
|
before_action :authenticate_user!
|
370
385
|
|
371
386
|
def my_action
|
372
|
-
|
387
|
+
result = DummySchema.execute(params[:query], context: current_user: current_user)
|
388
|
+
render json: result unless performed?
|
373
389
|
end
|
374
390
|
end
|
375
391
|
```
|
376
392
|
|
377
|
-
The install generator can
|
378
|
-
|
379
|
-
If authentication fails for the request for whatever reason, execution of the request is halted
|
380
|
-
and an error is returned in a REST format as the request never reaches your GQL schema.
|
393
|
+
The install generator can include the concern in you application controller.
|
394
|
+
If authentication fails for a request, execution will halt and a REST error will be returned since the request never reaches your GQL schema.
|
381
395
|
|
382
396
|
#### Authenticate in Your GQL Schema
|
383
397
|
For this you will need to add the `GraphqlDevise::SchemaPlugin` to your schema as described
|
@@ -390,7 +404,8 @@ class MyController < ApplicationController
|
|
390
404
|
include GraphqlDevise::Concerns::SetUserByToken
|
391
405
|
|
392
406
|
def my_action
|
393
|
-
|
407
|
+
result = DummySchema.execute(params[:query], context: graphql_context(:user))
|
408
|
+
render json: result unless performed?
|
394
409
|
end
|
395
410
|
end
|
396
411
|
```
|
@@ -427,32 +442,28 @@ module Types
|
|
427
442
|
end
|
428
443
|
```
|
429
444
|
|
445
|
+
#### Important
|
446
|
+
Remember to check `performed?` before rendering the result of the graphql operation. This is required because some operations perform a redirect and without this check you will get a `AbstractController::DoubleRenderError`.
|
447
|
+
|
430
448
|
### Making Requests
|
431
449
|
Here is a list of the available mutations and queries assuming your mounted model is `User`.
|
432
450
|
|
433
451
|
#### Mutations
|
434
|
-
1. `userLogin(email: String!, password: String!): UserLoginPayload`
|
435
|
-
|
436
|
-
This mutation has a second field by default. `credentials` can be fetched directly on the mutation return type.
|
437
|
-
Credentials are still returned in the headers of the response.
|
438
|
-
|
439
|
-
1. `userLogout: UserLogoutPayload`
|
440
|
-
1. `userSignUp(email: String!, password: String!, passwordConfirmation: String!, confirmSuccessUrl: String): UserSignUpPayload`
|
441
|
-
|
442
|
-
The parameter `confirmSuccessUrl` is optional unless you are using the `confirmable` plugin from Devise in your `resource`'s model. If you have `confirmable` set up, you will have to provide it unless you have `config.default_confirm_success_url` set in `config/initializers/devise_token_auth.rb`.
|
443
|
-
1. `userSendResetPassword(email: String!, redirectUrl: String!): UserSendReserPasswordPayload`
|
444
|
-
1. `userUpdatePassword(password: String!, passwordConfirmation: String!, currentPassword: String): UserUpdatePasswordPayload`
|
445
|
-
|
446
|
-
The parameter `currentPassword` is optional if you have `config.check_current_password_before_update` set to
|
447
|
-
false (disabled by default) on your generated `config/initializers/devise_token_aut.rb` or if the `resource`
|
448
|
-
model supports the `recoverable` Devise plugin and the `resource`'s `allow_password_change` attribute is set to true (this is done in the `userCheckPasswordToken` query when you click on the sent email's link).
|
449
|
-
1. `userResendConfirmation(email: String!, redirectUrl: String!): UserResendConfirmationPayload`
|
450
452
|
|
451
|
-
|
453
|
+
Operation | Description | Example
|
454
|
+
:--- | :--- | :------------------:
|
455
|
+
login | This mutation has a second field by default. `credentials` can be fetched directly on the mutation return type.<br>Credentials are still returned in the headers of the response. | userLogin(email: String!, password: String!): UserLoginPayload
|
456
|
+
logout | | userLogout: UserLogoutPayload
|
457
|
+
signUp | The parameter `confirmSuccessUrl` is optional unless you are using the `confirmable` plugin from Devise in your `resource`'s model. If you have `confirmable` set up, you will have to provide it unless you have `config.default_confirm_success_url` set in `config/initializers/devise_token_auth.rb`. | userSignUp(email: String!, password: String!, passwordConfirmation: String!, confirmSuccessUrl: String): UserSignUpPayload
|
458
|
+
sendResetPassword | | userSendResetPassword(email: String!, redirectUrl: String!): UserSendReserPasswordPayload
|
459
|
+
updatePassword | The parameter `currentPassword` is optional if you have `config.check_current_password_before_update` set to false (disabled by default) on your generated `config/initializers/devise_token_aut.rb` or if the `resource` model supports the `recoverable` Devise plugin and the `resource`'s `allow_password_change` attribute is set to true (this is done in the `userCheckPasswordToken` query when you click on the sent email's link). | userUpdatePassword(password: String!, passwordConfirmation: String!, currentPassword: String): UserUpdatePasswordPayload
|
460
|
+
resendConfirmation | The `UserResendConfirmationPayload` will return the `authenticatable` resource that was sent the confirmation instructions but also has a `message: String!` that can be used to notify a user what to do after the instructions were sent to them | userResendConfirmation(email: String!, redirectUrl: String!): UserResendConfirmationPayload
|
452
461
|
|
453
462
|
#### Queries
|
454
|
-
|
455
|
-
|
463
|
+
Operation | Description | Example
|
464
|
+
:--- | :--- | :------------------:
|
465
|
+
confirmAccount | Performs a redirect using the `redirectUrl` param | userConfirmAccount(confirmationToken: String!, redirectUrl: String!): User
|
466
|
+
checkPasswordToken | Performs a redirect using the `redirectUrl` param | userCheckPasswordToken(resetPasswordToken: String!, redirectUrl: String): User
|
456
467
|
|
457
468
|
The reason for having 2 queries is that these 2 are going to be accessed when clicking on
|
458
469
|
the confirmation and reset password email urls. There is no limitation for making mutation
|
@@ -5,7 +5,7 @@ module GraphqlDevise
|
|
5
5
|
source_root File.expand_path('templates', __dir__)
|
6
6
|
|
7
7
|
argument :user_class, type: :string, default: 'User'
|
8
|
-
argument :mount_path, type: :string, default: '
|
8
|
+
argument :mount_path, type: :string, default: 'graphql_auth'
|
9
9
|
|
10
10
|
class_option :mount, type: :string, default: 'separate_route'
|
11
11
|
|
@@ -8,6 +8,11 @@ module GraphqlDevise
|
|
8
8
|
argument :password_confirmation, String, required: true
|
9
9
|
argument :confirm_success_url, String, required: false
|
10
10
|
|
11
|
+
field :credentials,
|
12
|
+
GraphqlDevise::Types::CredentialType,
|
13
|
+
null: true,
|
14
|
+
description: 'Authentication credentials. Null if after signUp resource is not active for authentication (e.g. Email confirmation required).'
|
15
|
+
|
11
16
|
def resolve(confirm_success_url: nil, **attrs)
|
12
17
|
resource = build_resource(attrs.merge(provider: provider))
|
13
18
|
raise_user_error(I18n.t('graphql_devise.resource_build_failed')) if resource.blank?
|
@@ -34,9 +39,11 @@ module GraphqlDevise
|
|
34
39
|
)
|
35
40
|
end
|
36
41
|
|
37
|
-
|
42
|
+
response_payload = { authenticatable: resource }
|
43
|
+
|
44
|
+
response_payload[:credentials] = set_auth_headers(resource) if resource.active_for_authentication?
|
38
45
|
|
39
|
-
|
46
|
+
response_payload
|
40
47
|
else
|
41
48
|
resource.try(:clean_up_passwords)
|
42
49
|
raise_user_error_list(
|
@@ -41,7 +41,7 @@ RSpec.describe GraphqlDevise::InstallGenerator, type: :generator do
|
|
41
41
|
let(:args) { [] }
|
42
42
|
|
43
43
|
it 'creates and updated required files' do
|
44
|
-
assert_file 'config/routes.rb', /^\s{2}mount_graphql_devise_for 'User', at: '
|
44
|
+
assert_file 'config/routes.rb', /^\s{2}mount_graphql_devise_for 'User', at: 'graphql_auth'/
|
45
45
|
expect(routes_content).not_to match(dta_route)
|
46
46
|
|
47
47
|
assert_file 'config/initializers/devise.rb'
|
@@ -21,6 +21,7 @@ RSpec.describe 'Sign Up process' do
|
|
21
21
|
passwordConfirmation: "#{password}"
|
22
22
|
confirmSuccessUrl: "#{redirect}"
|
23
23
|
) {
|
24
|
+
credentials { accessToken }
|
24
25
|
user {
|
25
26
|
email
|
26
27
|
name
|
@@ -43,7 +44,8 @@ RSpec.describe 'Sign Up process' do
|
|
43
44
|
expect(user.confirmed_at).to be_nil
|
44
45
|
expect(user).to be_valid_password(password)
|
45
46
|
expect(json_response[:data][:userSignUp]).to include(
|
46
|
-
|
47
|
+
credentials: nil,
|
48
|
+
user: {
|
47
49
|
email: email,
|
48
50
|
name: name
|
49
51
|
}
|
@@ -126,6 +128,7 @@ RSpec.describe 'Sign Up process' do
|
|
126
128
|
passwordConfirmation: "#{password}"
|
127
129
|
confirmSuccessUrl: "#{redirect}"
|
128
130
|
) {
|
131
|
+
credentials { accessToken client uid }
|
129
132
|
authenticatable {
|
130
133
|
email
|
131
134
|
}
|
@@ -134,8 +137,16 @@ RSpec.describe 'Sign Up process' do
|
|
134
137
|
GRAPHQL
|
135
138
|
end
|
136
139
|
|
137
|
-
it '
|
140
|
+
it 'returns credentials as no confirmation is required' do
|
138
141
|
expect { post_request }.to change(Guest, :count).from(0).to(1)
|
142
|
+
|
143
|
+
expect(json_response[:data][:guestSignUp]).to include(
|
144
|
+
authenticatable: { email: email },
|
145
|
+
credentials: hash_including(
|
146
|
+
uid: email,
|
147
|
+
client: Guest.last.tokens.keys.first
|
148
|
+
)
|
149
|
+
)
|
139
150
|
end
|
140
151
|
end
|
141
152
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: graphql_devise
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.13.
|
4
|
+
version: 0.13.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Mario Celi
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: exe
|
11
11
|
cert_chain: []
|
12
|
-
date: 2020-
|
12
|
+
date: 2020-07-30 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: devise_token_auth
|