ibrain-auth 0.2.6 → 0.2.7
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 +4 -4
- data/app/graphql/ibrain/auth/mutations/generate_firebase_token_mutation.rb +35 -0
- data/app/graphql/ibrain/auth/types/input/generate_firebase_token_input.rb +13 -0
- data/app/repositories/firebase_repository.rb +41 -0
- data/lib/generators/ibrain/auth/install/templates/config/initializers/ibrain_auth.rb.tt +9 -0
- data/lib/ibrain/auth/version.rb +2 -2
- data/lib/ibrain/auth_configuration.rb +9 -0
- metadata +6 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9deb56fb20025aafc070789b5bfa07422ed6d101c176d02650222e9a79b32736
|
4
|
+
data.tar.gz: 466ef586478d5c5643982d369a85da485601dcaec871b32a7bf7423e089d141b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3d92287766c4a26ee54357eb4f966ac4a51a0417228a2f8ba47f779eff4b316e2821f637863be06c18460a5ce2150fe062150653dfc9c3f3a66a567b98a623f0
|
7
|
+
data.tar.gz: 5a20e97b2e6a721f592c8cb4b0a27624c430a4a18e1bb80406328d42efc6ef1e9d787af93564767e17e728992efe8b0cc361840efae12d5353d09058ff6bd6f8
|
@@ -0,0 +1,35 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Ibrain::Auth::Mutations
|
4
|
+
class GenerateFirebaseTokenMutation < BaseMutation
|
5
|
+
field :result, Boolean, null: true
|
6
|
+
field :token, String, null: true
|
7
|
+
|
8
|
+
argument :attributes, ::Ibrain::Auth::Types::Input::GenerateFirebaseTokenInput, required: true
|
9
|
+
|
10
|
+
def resolve(_args)
|
11
|
+
token = repo.generate_custom_token!
|
12
|
+
|
13
|
+
graphql_returning(token)
|
14
|
+
end
|
15
|
+
|
16
|
+
private
|
17
|
+
|
18
|
+
def normalize_parameters
|
19
|
+
attribute_params.permit(:uid)
|
20
|
+
rescue StandardError
|
21
|
+
ActionController::Parameters.new({})
|
22
|
+
end
|
23
|
+
|
24
|
+
def repo
|
25
|
+
::FirebaseRepository.new(nil, normalize_parameters)
|
26
|
+
end
|
27
|
+
|
28
|
+
def graphql_returning(token)
|
29
|
+
OpenStruct.new(
|
30
|
+
token: token,
|
31
|
+
result: true
|
32
|
+
)
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
@@ -0,0 +1,41 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
class FirebaseRepository < Ibrain::BaseRepository
|
4
|
+
def initialize(record, _params)
|
5
|
+
super(nil, record)
|
6
|
+
|
7
|
+
@private_key_json = File.open(Ibrain::Auth::Config.firebase_private_key_path).read
|
8
|
+
@firebase_owner_email = Ibrain::Auth::Config.firebase_owner_email
|
9
|
+
end
|
10
|
+
|
11
|
+
def generate_custom_token!
|
12
|
+
now = Time.now.to_i
|
13
|
+
|
14
|
+
payload = {
|
15
|
+
iss: firebase_owner_email,
|
16
|
+
sub: firebase_owner_email,
|
17
|
+
aud: Ibrain::Auth::Config.firebase_aud_url,
|
18
|
+
iat: now,
|
19
|
+
exp: now + 3600,
|
20
|
+
uid: params[:uid],
|
21
|
+
claims: {}
|
22
|
+
}
|
23
|
+
|
24
|
+
JWT.encode payload, private_key, "RS256"
|
25
|
+
end
|
26
|
+
|
27
|
+
private
|
28
|
+
|
29
|
+
attr_reader :private_key_json, :firebase_owner_email
|
30
|
+
|
31
|
+
def method_name
|
32
|
+
end
|
33
|
+
|
34
|
+
def json_firebase
|
35
|
+
JSON.parse(private_key_json, symbolize_names: true)
|
36
|
+
end
|
37
|
+
|
38
|
+
def private_key
|
39
|
+
OpenSSL::PKey::RSA.new json_firebase[:private_key]
|
40
|
+
end
|
41
|
+
end
|
@@ -16,4 +16,13 @@ Ibrain::Auth.config do |config|
|
|
16
16
|
|
17
17
|
# sign_in graphql input
|
18
18
|
config.sign_up_input = Ibrain::Auth::Types::Input::SignInInput
|
19
|
+
|
20
|
+
# firebase private json path
|
21
|
+
config.firebase_private_key_path = Rails.root.join('static/firebase.json')
|
22
|
+
|
23
|
+
# firebase aud url
|
24
|
+
config.firebase_auth_url = "https://identitytoolkit.googleapis.com/google.identity.identitytoolkit.v1.IdentityToolkit"
|
25
|
+
|
26
|
+
# firebase owner email
|
27
|
+
config.firebase_owner_email = nil
|
19
28
|
end
|
data/lib/ibrain/auth/version.rb
CHANGED
@@ -4,14 +4,14 @@ module Ibrain
|
|
4
4
|
# frozen_string_literal: true
|
5
5
|
|
6
6
|
module Auth
|
7
|
-
VERSION = '0.2.
|
7
|
+
VERSION = '0.2.7'
|
8
8
|
|
9
9
|
def self.ibrain_auth_version
|
10
10
|
VERSION
|
11
11
|
end
|
12
12
|
|
13
13
|
def self.previous_ibrain_auth_minor_version
|
14
|
-
'0.2.
|
14
|
+
'0.2.6'
|
15
15
|
end
|
16
16
|
|
17
17
|
def self.ibrain_auth_gem_version
|
@@ -17,5 +17,14 @@ module Ibrain
|
|
17
17
|
|
18
18
|
# sign_in input
|
19
19
|
preference :sign_in_input, :class, default: Ibrain::Auth::Types::Input::SignInInput
|
20
|
+
|
21
|
+
# firebase private json path
|
22
|
+
preference :firebase_private_key_path, :string, default: Rails.root.join('static/firebase.json')
|
23
|
+
|
24
|
+
# firebase aud url
|
25
|
+
preference :firebase_auth_url, :string, default: "https://identitytoolkit.googleapis.com/google.identity.identitytoolkit.v1.IdentityToolkit"
|
26
|
+
|
27
|
+
# firebase owner email
|
28
|
+
preference :firebase_owner_email, :string, default: nil
|
20
29
|
end
|
21
30
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ibrain-auth
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.7
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Tai Nguyen Van
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2022-
|
11
|
+
date: 2022-10-01 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: devise-encryptable
|
@@ -194,15 +194,18 @@ files:
|
|
194
194
|
- app/controllers/ibrain/auth/sessions_controller.rb
|
195
195
|
- app/controllers/ibrain/auth/unlocks_controller.rb
|
196
196
|
- app/graphql/ibrain/auth/mutations/base_mutation.rb
|
197
|
+
- app/graphql/ibrain/auth/mutations/generate_firebase_token_mutation.rb
|
197
198
|
- app/graphql/ibrain/auth/mutations/sign_in_mutation.rb
|
198
199
|
- app/graphql/ibrain/auth/mutations/sign_out_mutation.rb
|
199
200
|
- app/graphql/ibrain/auth/mutations/sign_up_mutation.rb
|
200
201
|
- app/graphql/ibrain/auth/mutations/social_sign_in_mutation.rb
|
202
|
+
- app/graphql/ibrain/auth/types/input/generate_firebase_token_input.rb
|
201
203
|
- app/graphql/ibrain/auth/types/input/sign_in_input.rb
|
202
204
|
- app/graphql/ibrain/auth/types/input/sign_up_input.rb
|
203
205
|
- app/models/ibrain/auth/user.rb
|
204
206
|
- app/repositories/apple_repository.rb
|
205
207
|
- app/repositories/auth_repository.rb
|
208
|
+
- app/repositories/firebase_repository.rb
|
206
209
|
- app/repositories/twitter_repository.rb
|
207
210
|
- config/initializers/devise.rb
|
208
211
|
- config/locales/en.yml
|
@@ -245,7 +248,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
245
248
|
- !ruby/object:Gem::Version
|
246
249
|
version: '0'
|
247
250
|
requirements: []
|
248
|
-
rubygems_version: 3.
|
251
|
+
rubygems_version: 3.2.22
|
249
252
|
signing_key:
|
250
253
|
specification_version: 4
|
251
254
|
summary: Its Auth is an sso authen gem for Ruby on Rails.
|