firebase_auth_latest 0.1.0 → 0.1.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: 92c8273dbbaaa3ec91ffb94148f8892215d6ac4fb0881c79be2324bbefe33439
4
- data.tar.gz: b07edf32f789c6248481490e0432bcb3b8758aabdc003e86e76a255e0f6d789b
3
+ metadata.gz: e3d63ece1617b8f2646e471c507f5600c28c2cbd3e84bae1558ec36e47863bc0
4
+ data.tar.gz: 190cba8775f38ff2e721ca5634b92db92bfb9ce80927e2c0bf5d708abee5317a
5
5
  SHA512:
6
- metadata.gz: 24b35b9c3644d166d4ee90ab5338b34008186749829374b0642bebb6b9fd5ece17f38ffe92155e848a262a0146c57d83ea46c26a06283670478ed87850a0fb5e
7
- data.tar.gz: c29018d7a35c872e835209ec70586509153c01fcaa1f2ec8f60988495f5e809f7525c8c0402dbb3ecb03221ffe6ae09187f9d268e13a7b899df055ecf4b2bd28
6
+ metadata.gz: 6577f889809fb8588afc5ba7b097fcaa09d9f6a2d54da324cc16d44dae6c509eb7df42eaf8a2945b2a5ea4b40dd8324236d925584dfabd487020cb8a34e3c9e5
7
+ data.tar.gz: fad1972182946dd6b23a526a1e2dedb3ea284965b8830ea4da81d9bd6a1564e4a24ae1bd472fd7b277c1f05f0ec266eec14170ed20535b72267101ce71209af7
@@ -0,0 +1,15 @@
1
+ require 'rails/railtie'
2
+
3
+ module FirebaseAuth
4
+ class Railtie < Rails::Railtie
5
+ railtie_name :firebase_auth_service
6
+
7
+ rake_tasks do
8
+ load "tasks/firebase_auth_tasks.rake"
9
+ end
10
+
11
+ generators do
12
+ require "generators/firebase_auth/model_generator"
13
+ end
14
+ end
15
+ end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module FirebaseAuth
4
- VERSION = "0.1.0"
4
+ VERSION = "0.1.2"
5
5
  end
data/lib/firebase_auth.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  require "firebase_auth/version"
2
- require "firebase_auth/firebase_auth_service"
2
+ require "firebase_auth/firebase_auth"
3
3
  require "firebase_auth/user"
4
4
 
5
5
  module FirebaseAuth
@@ -0,0 +1,39 @@
1
+ require 'rails/generators'
2
+
3
+ module FirebaseAuth
4
+ module Generators
5
+ class ModelGenerator < Rails::Generators::NamedBase
6
+ source_root File.expand_path('templates', __dir__)
7
+
8
+ def create_model_file
9
+ template 'model.rb.tt', File.join('app/models', class_path, "#{file_name}.rb")
10
+ end
11
+
12
+ def create_migration_file
13
+ generate 'migration', "Create#{class_name.pluralize} email:string user_id:string"
14
+ end
15
+
16
+ def inject_authenticate_method
17
+ inject_into_class 'app/controllers/application_controller.rb', ApplicationController do
18
+ <<-RUBY
19
+
20
+ before_action :authenticate_#{file_name}
21
+
22
+ private
23
+
24
+ def authenticate_#{file_name}
25
+ id_token = request.headers['Authorization']&.split(' ')&.last
26
+ if id_token
27
+ decoded_token = FirebaseAuthService::FirebaseAuthService.new(Rails.application.credentials.dig(:firebase, :project_id)).verify_id_token(id_token)
28
+ if decoded_token
29
+ @current_#{file_name} = #{class_name}.find_by(email: decoded_token['email'])
30
+ end
31
+ end
32
+ render json: { error: 'Unauthorized' }, status: :unauthorized unless @current_#{file_name}
33
+ end
34
+ RUBY
35
+ end
36
+ end
37
+ end
38
+ end
39
+ end
@@ -0,0 +1,4 @@
1
+ class <%= class_name %> < ApplicationRecord
2
+ validates :email, presence: true, uniqueness: true
3
+ validates :user_id, presence: true, uniqueness: true
4
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: firebase_auth_latest
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Taha Ali Irfan
@@ -52,6 +52,20 @@ dependencies:
52
52
  - - ">="
53
53
  - !ruby/object:Gem::Version
54
54
  version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rails
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '5.0'
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '5.0'
55
69
  description: A gem for integrating Firebase Authentication into your Rails application..
56
70
  email:
57
71
  - tahairfan1993@gmail.com
@@ -63,8 +77,11 @@ files:
63
77
  - README.md
64
78
  - lib/firebase_auth.rb
65
79
  - lib/firebase_auth/firebase_auth.rb
80
+ - lib/firebase_auth/railtie.rb
66
81
  - lib/firebase_auth/user.rb
67
82
  - lib/firebase_auth/version.rb
83
+ - lib/generators/firebase_auth/model_generator.rb
84
+ - lib/generators/templates/model.rb.tt
68
85
  homepage: https://github.com/tahairfan13/firebase_auth
69
86
  licenses:
70
87
  - MIT