graphql-auth 0.2.2 → 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 24b297147c7a9202042b30f341360b9d4ce44adbbe4599aac1d74e6f06e389d9
4
- data.tar.gz: f5adbf79ef720f3a158a83ff683166bb4f189c97aa09c6b2c5d7a81cd7000758
3
+ metadata.gz: 2d9b9e3eebb716abb0ae389627c8006f6e83c59a524d0a47952f4ca7b5ae71b0
4
+ data.tar.gz: ea1d59f34080c3f8de6c93ca863896749e2eee33c639ddd03a04769634dd5978
5
5
  SHA512:
6
- metadata.gz: 70adf1122986d5a0f1fc7d44fa23e131bc893377168e9640b6ddf8a78b7c76c47285188480131bb936d1ef2352ab348bbf750d7803d41ba0992b5f30f3d42668
7
- data.tar.gz: 200f41cc0b592477fcae5be164eeaa5b11541fb7044fecea4659566db656b7b35f088fb0fc79aeed43dfe0e90b879d3426948e38d5c37d67ce6fe872e49feafc
6
+ metadata.gz: e63952bea921336b3e583af3f27eba1dde05b1fd21004be8d6eefd97086d51b0535b6290f065ff6a9683ec17d3e20661a584d123756d079552c07a7eeeb3e365
7
+ data.tar.gz: e10144fa6c1d8ded3de6f4f0e4f4d449c4a4561485c9a03910e776d1c3d9b4f346ed224c7dae4d5efdbd2c7579924018f54ae7da14351f042d45777b013fecb9
data/README.md CHANGED
@@ -1,4 +1,6 @@
1
- # GraphQL Auth
1
+ # GraphQL Auth
2
+
3
+ [![Build Status](https://travis-ci.org/o2web/graphql-auth.svg?branch=master)](https://travis-ci.org/o2web/graphql-auth) [![Maintainability](https://api.codeclimate.com/v1/badges/7e2515bb59f0b205a603/maintainability)](https://codeclimate.com/github/o2web/graphql-auth/maintainability)
2
4
 
3
5
  Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/graphql-auth`. To experiment with that code, run `bin/console` for an interactive prompt.
4
6
 
@@ -26,14 +28,14 @@ rails g graphql_auth:install
26
28
 
27
29
  Make sure to read all configurations present inside the file and fill them with your own configs.
28
30
 
29
- ## Devise gem
31
+ ## Devise gem
30
32
 
31
- Use Devise with a User model and skip all route
33
+ Use Devise with a User model and skip all route
32
34
 
33
- ```
34
- Rails.application.routes.draw do
35
- devise_for :users, skip: :all
36
- end
35
+ ```
36
+ Rails.application.routes.draw do
37
+ devise_for :users, skip: :all
38
+ end
37
39
  ```
38
40
 
39
41
  ## Usage
data/Rakefile ADDED
@@ -0,0 +1,18 @@
1
+ begin
2
+ require 'bundler/setup'
3
+ rescue LoadError
4
+ puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
5
+ end
6
+
7
+ APP_RAKEFILE = File.expand_path('spec/dummy/Rakefile', __dir__)
8
+ load 'rails/tasks/engine.rake'
9
+
10
+ require 'rake'
11
+ require 'rspec/core/rake_task'
12
+
13
+ RSpec::Core::RakeTask.new(:spec) do |t|
14
+ t.pattern = Dir.glob('spec/**/*_spec.rb')
15
+ t.rspec_opts = '--format documentation'
16
+ end
17
+
18
+ task default: :spec
@@ -1,12 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- # mutation {
4
- # forgotPassword(email: "email@example.com") {
5
- # valid
6
- # success
7
- # }
8
- # }
9
-
10
3
  class Mutations::Auth::ForgotPassword < GraphQL::Schema::Mutation
11
4
  argument :email, String, required: true do
12
5
  description 'The email with forgotten password'
@@ -14,6 +7,7 @@ class Mutations::Auth::ForgotPassword < GraphQL::Schema::Mutation
14
7
 
15
8
  field :errors, [::Types::Auth::Error], null: false
16
9
  field :success, Boolean, null: false
10
+ field :valid, Boolean, null: false
17
11
 
18
12
  def resolve(email:)
19
13
  user = User.find_by email: email
@@ -1,15 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- # mutation {
4
- # resetPassword(resetPasswordToken: "token", password: "password", passwordConfirmation: "password") {
5
- # success
6
- # errors {
7
- # field
8
- # message
9
- # }
10
- # }
11
- # }
12
-
13
3
  class Mutations::Auth::ResetPassword < GraphQL::Schema::Mutation
14
4
  argument :reset_password_token, String, required: true do
15
5
  description "Reset password token"
@@ -1,18 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- # mutation {
4
- # signIn(email: "email@example.com", password: "password") {
5
- # success
6
- # user {
7
- # email
8
- # }
9
- # errors {
10
- # field
11
- # message
12
- # }
13
- # }
14
- # }
15
-
16
3
  class Mutations::Auth::SignIn < GraphQL::Schema::Mutation
17
4
  include ::Graphql::TokenHelper
18
5
 
@@ -1,18 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- # mutation {
4
- # signUp(email: "email@example.com", password: "password", passwordConfirmation: "password") {
5
- # success
6
- # user {
7
- # email
8
- # }
9
- # errors {
10
- # field
11
- # message
12
- # }
13
- # }
14
- # }
15
-
16
3
  class Mutations::Auth::SignUp < GraphQL::Schema::Mutation
17
4
  include ::Graphql::TokenHelper
18
5
 
@@ -1,18 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- # mutation {
4
- # updateAccount(current_password: "currentPassword", password: "newPassword", password_confirmation: "newPassword") {
5
- # success
6
- # user {
7
- # email
8
- # }
9
- # errors {
10
- # field
11
- # message
12
- # }
13
- # }
14
- # }
15
-
16
3
  class Mutations::Auth::UpdateAccount < GraphQL::Schema::Mutation
17
4
  argument :current_password, String, required: true do
18
5
  description "User's current password"
@@ -32,6 +19,17 @@ class Mutations::Auth::UpdateAccount < GraphQL::Schema::Mutation
32
19
 
33
20
  def resolve(args)
34
21
  user = context[:current_user]
22
+
23
+ if user.blank?
24
+ return {
25
+ errors: [
26
+ { field: :_error, message: I18n.t('devise.failure.unauthenticated') }
27
+ ],
28
+ success: false,
29
+ user: nil
30
+ }
31
+ end
32
+
35
33
  user.update_with_password args
36
34
 
37
35
  if user.errors.any?
@@ -1,15 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- # mutation {
4
- # validateToken {
5
- # success
6
- # valid
7
- # user {
8
- # email
9
- # }
10
- # }
11
- # }
12
-
13
3
  class Mutations::Auth::ValidateToken < GraphQL::Schema::Mutation
14
4
  field :errors, [::Types::Auth::Error], null: false
15
5
  field :success, Boolean, null: false
@@ -26,4 +16,4 @@ class Mutations::Auth::ValidateToken < GraphQL::Schema::Mutation
26
16
  valid: user.present?,
27
17
  }
28
18
  end
29
- end
19
+ end
@@ -4,8 +4,11 @@ module GraphqlAuth
4
4
  source_root File.expand_path('../templates', __FILE__)
5
5
 
6
6
  def copy_configuration
7
- template 'initializer.rb', 'config/initializers/graphql_auth.rb'
8
- template 'add_refresh_token_to_user.rb', "db/migrate/#{Time.now.strftime('%Y%m%d%H%M%S')}_add_refresh_token_to_user.rb"
7
+ template 'graphql_auth.rb.erb', 'config/initializers/graphql_auth.rb'
8
+ end
9
+
10
+ def rake_db
11
+ rake("railties:install:migrations")
9
12
  end
10
13
  end
11
14
  end
@@ -14,4 +14,4 @@ GraphQL::Auth.configure do |config|
14
14
  # config.update_account_mutation = ::Mutations::Auth::UpdateAccount
15
15
 
16
16
  # config.validate_token_mutation = ::Mutations::Auth::ValidateToken
17
- end
17
+ end
data/lib/graphql-auth.rb CHANGED
@@ -1,4 +1,5 @@
1
1
  require 'devise'
2
+ require 'graphql'
2
3
  require 'graphql-auth/configuration'
3
4
  require 'graphql-auth/engine'
4
5
  require 'graphql-auth/reset_password'
@@ -1,7 +1,9 @@
1
1
  module GraphQL
2
2
  module Auth
3
3
  class Engine < ::Rails::Engine
4
+ isolate_namespace GraphQL::Auth
5
+
4
6
  config.autoload_paths += Dir["#{config.root}/app/**/"]
5
7
  end
6
8
  end
7
- end
9
+ end
@@ -0,0 +1,5 @@
1
+ module GraphQL
2
+ module Auth
3
+ VERSION = '0.3.0'
4
+ end
5
+ end
metadata CHANGED
@@ -1,43 +1,29 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: graphql-auth
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.2
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Guillaume Ferland
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-01-31 00:00:00.000000000 Z
11
+ date: 2019-02-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
- name: bundler
15
- requirement: !ruby/object:Gem::Requirement
16
- requirements:
17
- - - "~>"
18
- - !ruby/object:Gem::Version
19
- version: '1.15'
20
- type: :development
21
- prerelease: false
22
- version_requirements: !ruby/object:Gem::Requirement
23
- requirements:
24
- - - "~>"
25
- - !ruby/object:Gem::Version
26
- version: '1.15'
27
- - !ruby/object:Gem::Dependency
28
- name: rake
14
+ name: rails
29
15
  requirement: !ruby/object:Gem::Requirement
30
16
  requirements:
31
17
  - - "~>"
32
18
  - !ruby/object:Gem::Version
33
- version: '10.0'
34
- type: :development
19
+ version: '5.1'
20
+ type: :runtime
35
21
  prerelease: false
36
22
  version_requirements: !ruby/object:Gem::Requirement
37
23
  requirements:
38
24
  - - "~>"
39
25
  - !ruby/object:Gem::Version
40
- version: '10.0'
26
+ version: '5.1'
41
27
  - !ruby/object:Gem::Dependency
42
28
  name: graphql
43
29
  requirement: !ruby/object:Gem::Requirement
@@ -80,6 +66,76 @@ dependencies:
80
66
  - - "~>"
81
67
  - !ruby/object:Gem::Version
82
68
  version: '1.5'
69
+ - !ruby/object:Gem::Dependency
70
+ name: sqlite3
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: 1.3.6
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: 1.3.6
83
+ - !ruby/object:Gem::Dependency
84
+ name: bundler
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: '1.15'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: '1.15'
97
+ - !ruby/object:Gem::Dependency
98
+ name: rake
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - "~>"
102
+ - !ruby/object:Gem::Version
103
+ version: '10.0'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - "~>"
109
+ - !ruby/object:Gem::Version
110
+ version: '10.0'
111
+ - !ruby/object:Gem::Dependency
112
+ name: rspec
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - "~>"
116
+ - !ruby/object:Gem::Version
117
+ version: '3.0'
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - "~>"
123
+ - !ruby/object:Gem::Version
124
+ version: '3.0'
125
+ - !ruby/object:Gem::Dependency
126
+ name: database_cleaner
127
+ requirement: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - ">="
130
+ - !ruby/object:Gem::Version
131
+ version: '0'
132
+ type: :development
133
+ prerelease: false
134
+ version_requirements: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - ">="
137
+ - !ruby/object:Gem::Version
138
+ version: '0'
83
139
  description: GraphQL + JWT + Devise
84
140
  email:
85
141
  - ferland182@gmail.com
@@ -87,8 +143,8 @@ executables: []
87
143
  extensions: []
88
144
  extra_rdoc_files: []
89
145
  files:
90
- - Gemfile
91
146
  - README.md
147
+ - Rakefile
92
148
  - app/graphql/mutations/auth/forgot_password.rb
93
149
  - app/graphql/mutations/auth/reset_password.rb
94
150
  - app/graphql/mutations/auth/sign_in.rb
@@ -101,14 +157,15 @@ files:
101
157
  - app/helpers/graphql/auth_helper.rb
102
158
  - app/helpers/graphql/token_helper.rb
103
159
  - app/views/devise/mailer/reset_password_instructions.html.erb
160
+ - db/migrate/20190108151146_add_refresh_token_to_user.rb
104
161
  - lib/generators/graphql_auth/install_generator.rb
105
- - lib/generators/graphql_auth/templates/add_refresh_token_to_user.rb
106
- - lib/generators/graphql_auth/templates/initializer.rb
162
+ - lib/generators/graphql_auth/templates/graphql_auth.rb.erb
107
163
  - lib/graphql-auth.rb
108
164
  - lib/graphql-auth/configuration.rb
109
165
  - lib/graphql-auth/engine.rb
110
166
  - lib/graphql-auth/jwt_manager.rb
111
167
  - lib/graphql-auth/reset_password.rb
168
+ - lib/graphql-auth/version.rb
112
169
  homepage: https://github.com/o2web/graphql-auth
113
170
  licenses:
114
171
  - MIT
@@ -116,13 +173,12 @@ metadata: {}
116
173
  post_install_message:
117
174
  rdoc_options: []
118
175
  require_paths:
119
- - app
120
176
  - lib
121
177
  required_ruby_version: !ruby/object:Gem::Requirement
122
178
  requirements:
123
179
  - - ">="
124
180
  - !ruby/object:Gem::Version
125
- version: '0'
181
+ version: 2.4.5
126
182
  required_rubygems_version: !ruby/object:Gem::Requirement
127
183
  requirements:
128
184
  - - ">="
data/Gemfile DELETED
@@ -1,6 +0,0 @@
1
- source "https://rubygems.org"
2
-
3
- git_source(:github) {|repo_name| "https://github.com/#{repo_name}" }
4
-
5
- # Specify your gem's dependencies in graphql-devise-auth.gemspec
6
- gemspec