firebase-auth-rails 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/MIT-LICENSE +20 -0
- data/README.md +35 -0
- data/Rakefile +33 -0
- data/lib/firebase/auth/authenticable.rb +58 -0
- data/lib/firebase/auth/rails.rb +12 -0
- data/lib/firebase/auth/rails/version.rb +7 -0
- data/lib/firebase/auth/token.rb +33 -0
- data/lib/tasks/firebase/auth/rails_tasks.rake +4 -0
- metadata +136 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: f5a423b2f5c4765679b669b3e541fd5456a323a16918db802609721bb87c373a
|
4
|
+
data.tar.gz: aa2b928299b4bb2d4d13a29ba712ea4f21f4a83fefa8bf69107df5301cebd30a
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: f6d736e7dd9ff3a6ec561a5c57f36615ef69c82ca22688b0ac5fe33ebf935b1030f9bffcb08bd87ccb06198361b2d0c8fb23ecf2c66d6f91111355fee41f4a76
|
7
|
+
data.tar.gz: 31f4885688484cfd118922b674c1c853ac89233458bfbab5b125e0fadf1a666c8fc3aa1f631530b5e4f508b7a2430bd83076580a6ff859cfb9cd73ae5c92e875
|
data/MIT-LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright 2018 penguinwokrs
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,35 @@
|
|
1
|
+
# firebase-auth-rails
|
2
|
+
|
3
|
+
|
4
|
+
This is a plugin that performs firebase authentication in rails.
|
5
|
+
|
6
|
+
Made influenced by [firebase_id_token](https://github.com/fschuindt/firebase_id_token) and [knock](https://github.com/nsarno/knock)
|
7
|
+
|
8
|
+
Thanks to the author.
|
9
|
+
|
10
|
+
|
11
|
+
## Usage
|
12
|
+
How to use my plugin.
|
13
|
+
|
14
|
+
## Installation
|
15
|
+
Add this line to your application's Gemfile:
|
16
|
+
|
17
|
+
```ruby
|
18
|
+
gem 'firebase-auth-rails'
|
19
|
+
```
|
20
|
+
|
21
|
+
And then execute:
|
22
|
+
```bash
|
23
|
+
$ bundle
|
24
|
+
```
|
25
|
+
|
26
|
+
Or install it yourself as:
|
27
|
+
```bash
|
28
|
+
$ gem install firebase-auth-rails
|
29
|
+
```
|
30
|
+
|
31
|
+
## Contributing
|
32
|
+
|
33
|
+
|
34
|
+
## License
|
35
|
+
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
data/Rakefile
ADDED
@@ -0,0 +1,33 @@
|
|
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
|
+
require 'rdoc/task'
|
8
|
+
|
9
|
+
RDoc::Task.new(:rdoc) do |rdoc|
|
10
|
+
rdoc.rdoc_dir = 'rdoc'
|
11
|
+
rdoc.title = 'Firebase::Auth::Rails'
|
12
|
+
rdoc.options << '--line-numbers'
|
13
|
+
rdoc.rdoc_files.include('README.md')
|
14
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
15
|
+
end
|
16
|
+
|
17
|
+
|
18
|
+
|
19
|
+
|
20
|
+
|
21
|
+
|
22
|
+
require 'bundler/gem_tasks'
|
23
|
+
|
24
|
+
require 'rake/testtask'
|
25
|
+
|
26
|
+
Rake::TestTask.new(:test) do |t|
|
27
|
+
t.libs << 'test'
|
28
|
+
t.pattern = 'test/**/*_test.rb'
|
29
|
+
t.verbose = false
|
30
|
+
end
|
31
|
+
|
32
|
+
|
33
|
+
task default: :test
|
@@ -0,0 +1,58 @@
|
|
1
|
+
module Firebase::Auth::Authenticable
|
2
|
+
def authenticate_for entity_class
|
3
|
+
getter_name = "current_#{entity_class.to_s.parameterize.underscore}"
|
4
|
+
define_current_entity_getter(entity_class, getter_name)
|
5
|
+
public_send(getter_name)
|
6
|
+
end
|
7
|
+
|
8
|
+
private
|
9
|
+
|
10
|
+
def token
|
11
|
+
params[:token] || token_from_request_headers
|
12
|
+
end
|
13
|
+
|
14
|
+
def method_missing(method, *args)
|
15
|
+
prefix, entity_name = method.to_s.split('_', 2)
|
16
|
+
case prefix
|
17
|
+
when 'authenticate'
|
18
|
+
unauthorized_entity unless authenticate_entity(entity_name)
|
19
|
+
when 'current'
|
20
|
+
authenticate_entity(entity_name)
|
21
|
+
else
|
22
|
+
super
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
def authenticate_entity(entity_name)
|
27
|
+
if token
|
28
|
+
entity_class = entity_name.camelize.constantize
|
29
|
+
send(:authenticate_for, entity_class)
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
def unauthorized_entity
|
34
|
+
head(:unauthorized)
|
35
|
+
end
|
36
|
+
|
37
|
+
def token_from_request_headers
|
38
|
+
unless request.headers['Authorization'].nil?
|
39
|
+
request.headers['Authorization'].split.last
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
def define_current_entity_getter entity_class, getter_name
|
44
|
+
unless self.respond_to?(getter_name)
|
45
|
+
memoization_var_name = "@_#{getter_name}"
|
46
|
+
self.class.send(:define_method, getter_name) do
|
47
|
+
unless instance_variable_defined?(memoization_var_name)
|
48
|
+
# FIXME: change model class
|
49
|
+
# FIXME: error handling
|
50
|
+
_token = Firebase::Auth::Token.new(token: token)
|
51
|
+
current = _token.entity_for(entity_class)
|
52
|
+
instance_variable_set(memoization_var_name, current)
|
53
|
+
end
|
54
|
+
instance_variable_get(memoization_var_name)
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
module Firebase
|
2
|
+
module Auth
|
3
|
+
class Token
|
4
|
+
attr_reader :token
|
5
|
+
attr_reader :payload
|
6
|
+
|
7
|
+
def initialize(payload: {}, token: nil, verify_options: {})
|
8
|
+
set_public_key
|
9
|
+
@token = token
|
10
|
+
@payload = FirebaseIdToken::Signature.verify(token)
|
11
|
+
# user not found or decode error
|
12
|
+
raise StandardError, 'decode error' if @payload.nil?
|
13
|
+
end
|
14
|
+
|
15
|
+
def entity_for(entity_class)
|
16
|
+
if entity_class.respond_to? :from_token_payload
|
17
|
+
entity_class.from_token_payload @payload
|
18
|
+
else
|
19
|
+
# FIXME: error handling
|
20
|
+
entity_class.find_by!(uid: @payload['sub'])
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
def set_public_key
|
25
|
+
# FIXME: cache
|
26
|
+
return unless FirebaseIdToken::Certificates.blank? || 0 <= FirebaseIdToken::Certificates.ttl
|
27
|
+
FirebaseIdToken::Certificates.request
|
28
|
+
nil
|
29
|
+
end
|
30
|
+
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
metadata
ADDED
@@ -0,0 +1,136 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: firebase-auth-rails
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.2
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- penguinwokrs
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2018-07-20 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: sqlite3
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: redis
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: pry-rails
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: minitest-stub_any_instance
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: rails
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: 5.1.6
|
76
|
+
type: :runtime
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: 5.1.6
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: firebase_id_token
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - "~>"
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: 2.3.0
|
90
|
+
type: :runtime
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - "~>"
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: 2.3.0
|
97
|
+
description: Description of Firebase::Auth::Rails.
|
98
|
+
email:
|
99
|
+
- dev.and.penguin@gmail.com
|
100
|
+
executables: []
|
101
|
+
extensions: []
|
102
|
+
extra_rdoc_files: []
|
103
|
+
files:
|
104
|
+
- MIT-LICENSE
|
105
|
+
- README.md
|
106
|
+
- Rakefile
|
107
|
+
- lib/firebase/auth/authenticable.rb
|
108
|
+
- lib/firebase/auth/rails.rb
|
109
|
+
- lib/firebase/auth/rails/version.rb
|
110
|
+
- lib/firebase/auth/token.rb
|
111
|
+
- lib/tasks/firebase/auth/rails_tasks.rake
|
112
|
+
homepage: https://github.com/penguinwokrs/firebase-auth-rails
|
113
|
+
licenses:
|
114
|
+
- MIT
|
115
|
+
metadata: {}
|
116
|
+
post_install_message:
|
117
|
+
rdoc_options: []
|
118
|
+
require_paths:
|
119
|
+
- lib
|
120
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
121
|
+
requirements:
|
122
|
+
- - ">="
|
123
|
+
- !ruby/object:Gem::Version
|
124
|
+
version: '0'
|
125
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
126
|
+
requirements:
|
127
|
+
- - ">="
|
128
|
+
- !ruby/object:Gem::Version
|
129
|
+
version: '0'
|
130
|
+
requirements: []
|
131
|
+
rubyforge_project:
|
132
|
+
rubygems_version: 2.7.6
|
133
|
+
signing_key:
|
134
|
+
specification_version: 4
|
135
|
+
summary: Summary of Firebase::Auth::Rails.
|
136
|
+
test_files: []
|