contrib-auth 0.4.1 → 0.5.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: ef320c78fd097c24090a4635394bad139b57dbed7ef3e78998238afc9243dc10
4
- data.tar.gz: f0482456dd9e97403bcaf3c2015d44c28154d61c86aa93721945aa3645ba855d
3
+ metadata.gz: 650de722f18cb838681c012c484328dec2d6c065e77025678b06c7e91bce4009
4
+ data.tar.gz: 0a7626a5fc3693968c5bee3adef83a91492f956e166be78e758919dadb4eed92
5
5
  SHA512:
6
- metadata.gz: 3ad3e8db46f1e149228455398dce3842ac964403e02f6e4c2dd4e90b38489954f8e5045cd13acf229e772d5900c3d8c674e206ea44ea9bdf67f239cbf699a495
7
- data.tar.gz: 155144638f18b43ab8e18cb065c26a4be7cc46c4ab1455f333127cfe1ee2d6546e928c211b54440435b895dee92f8494ae5fec237e2ff23f2b5e2ec8ce701bbb
6
+ metadata.gz: df833ef5f94a7d96b7ab9b7ce4c475fa40e29a29d71026c00dcc224684721ff5f74042cd5a109d7bd8c61a252253f591e440a8033feac8e9400e0d79344feb26
7
+ data.tar.gz: d335725a2e8188e342004551ccc29efa0443b76dd1f84e539df813cb052ea3c2ab8cd68c73f98565e4286245333d5b89a487cf15e6527a4bbd791e1998e798bf
@@ -23,6 +23,14 @@ module Contrib
23
23
  )
24
24
  end
25
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
+
26
34
  def certificates
27
35
  render json: Contrib::Auth.api.certificates, status: :ok
28
36
  end
@@ -0,0 +1 @@
1
+ json.extract!(@response, :id_token, :refresh_token, :expires_in, :email)
data/config/routes.rb CHANGED
@@ -2,7 +2,8 @@ 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
4
  post '/reset_password' => 'authentication#reset_password'
5
- post '/sign_up_with_email_or_username_and_password' => 'authentication#sign_up_with_email_or_username_and_password'
5
+ post '/change_password' => 'authentication#change_password'
6
6
  get '/certificates' => 'authentication#certificates'
7
+ post '/sign_up_with_email_or_username_and_password' => 'authentication#sign_up_with_email_or_username_and_password'
7
8
  end
8
9
  end
@@ -25,6 +25,12 @@ module Contrib
25
25
  @provider.sign_up_with_email_and_password(email_or_username, password)
26
26
  end
27
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
+
28
34
  def certificates
29
35
  @provider.certificates
30
36
  end
@@ -77,6 +77,28 @@ module Contrib
77
77
  response = @http_client.get(PUBLIC_KEYS_URI)
78
78
  JSON.parse(response.body)
79
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
80
102
  end
81
103
  end
82
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.4.1'
3
+ VERSION = '0.5.0'
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: contrib-auth
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.1
4
+ version: 0.5.0
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-29 00:00:00.000000000 Z
11
+ date: 2021-11-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -76,6 +76,7 @@ files:
76
76
  - app/jobs/contrib/auth/application_job.rb
77
77
  - app/mailers/contrib/auth/application_mailer.rb
78
78
  - app/models/contrib/auth/application_record.rb
79
+ - app/views/contrib/auth/authentication/change_password.json.jbuilder
79
80
  - app/views/contrib/auth/authentication/sign_in_with_password.json.jbuilder
80
81
  - app/views/contrib/auth/authentication/sign_up_with_email_or_username_and_password.json.jbuilder
81
82
  - config/routes.rb
@@ -85,6 +86,7 @@ files:
85
86
  - lib/contrib/auth/engine.rb
86
87
  - lib/contrib/auth/provider/google_auth.rb
87
88
  - lib/contrib/auth/provider/responses.rb
89
+ - lib/contrib/auth/provider/responses/change_password.rb
88
90
  - lib/contrib/auth/provider/responses/sign_in_with_password.rb
89
91
  - lib/contrib/auth/provider/responses/sign_up_with_email_and_password.rb
90
92
  - lib/contrib/auth/version.rb