contrib-auth 0.3.1 → 0.4.2

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: cb10ef1984df8036c7cc625c7560808a2da9e8613a953fbf3b2b715dbccab364
4
- data.tar.gz: 759d43d360a3c22b074963a41e5f69b9899dfb509b7db106da49a480cc7a3139
3
+ metadata.gz: 0c1695b4715a11c8631ac8a52cf6839a1497ecc621e87d4404bc2c7a6c14fe6a
4
+ data.tar.gz: 7c3702e193cae4e60772a35b3940691a90a34c56b8cd18cc8f1bbf508db876cb
5
5
  SHA512:
6
- metadata.gz: 41467b432ea48e15fd651813769e525b57e1af206e07c9afb628244a6b3dd71e11d1cd6e73322b07c9129d456544a00ee3211e6871a89b4523dc4ee77bdad2cc
7
- data.tar.gz: 9076f1eead44bc2ea93994484352ba77dd52558f45ff03d1fbb13ae626825a15f90540e50ef24fd510e1c81762f4625a10c0a9d856e7580ab7cfe28dc4d87132
6
+ metadata.gz: ac13c1ae9640fb29c2efde87293465e8a56b11d9a0103be1a838300b8ee57a77956a830aa538d527c8b75eef6ec66b009195bcc4c3700cb8d10221d0dbabe322
7
+ data.tar.gz: fb3750efea0e27c842ae6ab691639e66d0490af6fb29cefda8e56de850fe458ad5e41c1472813f543abd445045894b3d5cb5529c5897dc24f431a14ac0285d23
@@ -7,6 +7,33 @@ module Contrib
7
7
  params[:password]
8
8
  )
9
9
  end
10
+
11
+ def reset_password
12
+ @response = Contrib::Auth::api.reset_password(
13
+ params[:email_or_username]
14
+ )
15
+
16
+ render json: {}, status: :ok
17
+ end
18
+
19
+ def sign_up_with_email_or_username_and_password
20
+ @response = Contrib::Auth.api.sign_up_with_email_and_password(
21
+ params[:email_or_username],
22
+ params[:password]
23
+ )
24
+ end
25
+
26
+ def change_password
27
+ @response = Contrib::Auth.api.change_password(
28
+ params[:id_token],
29
+ params[:password],
30
+ params[:password_confirmation],
31
+ )
32
+ end
33
+
34
+ def certificates
35
+ render json: Contrib::Auth.api.certificates, status: :ok
36
+ end
10
37
  end
11
38
  end
12
39
  end
@@ -0,0 +1 @@
1
+ json.extract!(@response, :id_token, :refresh_token, :expires_in, :email)
@@ -0,0 +1 @@
1
+ json.extract!(@response, :id_token, :refresh_token, :expires_in)
data/config/routes.rb CHANGED
@@ -1,5 +1,9 @@
1
1
  Contrib::Auth::Engine.routes.draw do
2
2
  defaults format: :json do
3
3
  post '/sign_in_with_password' => 'authentication#sign_in_with_password'
4
+ post '/reset_password' => 'authentication#reset_password'
5
+ post '/change_password' => 'authentication#change_password'
6
+ get '/certificates' => 'authentication#certificates'
7
+ post '/sign_up_with_email_or_username_and_password' => 'authentication#sign_up_with_email_or_username_and_password'
4
8
  end
5
9
  end
@@ -6,7 +6,10 @@ module Contrib
6
6
  end
7
7
 
8
8
  def sign_in_with_password(email_or_username, password)
9
+ raise ArgumentError unless email_or_username
10
+ raise ArgumentError unless password
9
11
  # TODO: Implement retryable
12
+ # TODO: Validate incoming attributes
10
13
  @provider.sign_in_with_password(email_or_username, password)
11
14
  end
12
15
 
@@ -15,8 +18,22 @@ module Contrib
15
18
  end
16
19
 
17
20
  def sign_up_with_email_and_password(email_or_username, password)
21
+ raise ArgumentError unless email_or_username
22
+ raise ArgumentError unless password
23
+
24
+ # TODO: ask for password confirmation
18
25
  @provider.sign_up_with_email_and_password(email_or_username, password)
19
26
  end
27
+
28
+ def change_password(id_token, password, password_confirmation)
29
+ raise ArgumentError unless password == password_confirmation
30
+
31
+ @provider.change_password(id_token, password)
32
+ end
33
+
34
+ def certificates
35
+ @provider.certificates
36
+ end
20
37
  end
21
38
  end
22
39
  end
@@ -5,6 +5,7 @@ module Contrib
5
5
  module Provider
6
6
  class GoogleAuth
7
7
  DEFAULT_BASE_ENDPOINT = 'https://identitytoolkit.googleapis.com'.freeze
8
+ PUBLIC_KEYS_URI = 'https://www.googleapis.com/robot/v1/metadata/x509/securetoken@system.gserviceaccount.com'.freeze
8
9
 
9
10
  def initialize(api_key, http_client = Faraday.new(DEFAULT_BASE_ENDPOINT))
10
11
  @api_key = api_key
@@ -70,6 +71,34 @@ module Contrib
70
71
 
71
72
  response.success?
72
73
  end
74
+
75
+ # refers to: https://firebase.google.com/docs/auth/admin/verify-id-tokens
76
+ def certificates
77
+ response = @http_client.get(PUBLIC_KEYS_URI)
78
+ JSON.parse(response.body)
79
+ end
80
+
81
+ def change_password(id_token, password)
82
+ response = @http_client.post('/v1/accounts:update') do |req|
83
+ req.params[:key] = @api_key
84
+ req.headers['Content-Type'] = 'application/json'
85
+
86
+ req.body = JSON.generate(
87
+ idToken: id_token,
88
+ password: password,
89
+ returnSecureToken: true,
90
+ )
91
+ end
92
+
93
+ parsed_response = JSON.parse(response.body)
94
+
95
+ Contrib::Auth::Provider::Responses::ChangePassword.new(
96
+ id_token: parsed_response['idToken'],
97
+ refresh_token: parsed_response['refreshToken'],
98
+ expires_in: parsed_response['expiresIn'],
99
+ email: parsed_response['email'],
100
+ )
101
+ end
73
102
  end
74
103
  end
75
104
  end
@@ -0,0 +1,20 @@
1
+ module Contrib
2
+ module Auth
3
+ module Provider
4
+ module Responses
5
+ class ChangePassword
6
+ attr_accessor :id_token
7
+ attr_accessor :refresh_token
8
+ attr_accessor :expires_in
9
+ attr_accessor :email
10
+
11
+ def initialize(params = {})
12
+ params.each do |param, key|
13
+ public_send("#{param}=", key)
14
+ end
15
+ end
16
+ end
17
+ end
18
+ end
19
+ end
20
+ end
@@ -1,2 +1,3 @@
1
1
  require 'contrib/auth/provider/responses/sign_in_with_password'
2
2
  require 'contrib/auth/provider/responses/sign_up_with_email_and_password'
3
+ require 'contrib/auth/provider/responses/change_password'
@@ -1,5 +1,5 @@
1
1
  module Contrib
2
2
  module Auth
3
- VERSION = '0.3.1'
3
+ VERSION = '0.4.2'
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,22 +1,19 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: contrib-auth
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.1
4
+ version: 0.4.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Contribyard Developers
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-10-28 00:00:00.000000000 Z
11
+ date: 2023-07-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - "~>"
18
- - !ruby/object:Gem::Version
19
- version: 6.1.4
20
17
  - - ">="
21
18
  - !ruby/object:Gem::Version
22
19
  version: 6.1.4.1
@@ -24,9 +21,6 @@ dependencies:
24
21
  prerelease: false
25
22
  version_requirements: !ruby/object:Gem::Requirement
26
23
  requirements:
27
- - - "~>"
28
- - !ruby/object:Gem::Version
29
- version: 6.1.4
30
24
  - - ">="
31
25
  - !ruby/object:Gem::Version
32
26
  version: 6.1.4.1
@@ -76,7 +70,9 @@ files:
76
70
  - app/jobs/contrib/auth/application_job.rb
77
71
  - app/mailers/contrib/auth/application_mailer.rb
78
72
  - app/models/contrib/auth/application_record.rb
73
+ - app/views/contrib/auth/authentication/change_password.json.jbuilder
79
74
  - app/views/contrib/auth/authentication/sign_in_with_password.json.jbuilder
75
+ - app/views/contrib/auth/authentication/sign_up_with_email_or_username_and_password.json.jbuilder
80
76
  - config/routes.rb
81
77
  - lib/contrib/auth.rb
82
78
  - lib/contrib/auth/api.rb
@@ -84,6 +80,7 @@ files:
84
80
  - lib/contrib/auth/engine.rb
85
81
  - lib/contrib/auth/provider/google_auth.rb
86
82
  - lib/contrib/auth/provider/responses.rb
83
+ - lib/contrib/auth/provider/responses/change_password.rb
87
84
  - lib/contrib/auth/provider/responses/sign_in_with_password.rb
88
85
  - lib/contrib/auth/provider/responses/sign_up_with_email_and_password.rb
89
86
  - lib/contrib/auth/version.rb
@@ -108,7 +105,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
108
105
  - !ruby/object:Gem::Version
109
106
  version: '0'
110
107
  requirements: []
111
- rubygems_version: 3.2.22
108
+ rubygems_version: 3.4.10
112
109
  signing_key:
113
110
  specification_version: 4
114
111
  summary: Vendor-agnostic authentication component for Rails APIs