devise-fireauth 0.0.1.pre.alpha.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +11 -0
- data/.rspec +3 -0
- data/.travis.yml +7 -0
- data/CODE_OF_CONDUCT.md +74 -0
- data/Gemfile +6 -0
- data/Gemfile.lock +107 -0
- data/LICENSE.txt +21 -0
- data/README.md +76 -0
- data/Rakefile +6 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/devise-fireauth.gemspec +33 -0
- data/lib/devise/fireauth/models/firebase_authenticatable.rb +89 -0
- data/lib/devise/fireauth/strategies/firebase_authenticatable.rb +40 -0
- data/lib/devise/fireauth/version.rb +5 -0
- data/lib/devise/fireauth.rb +42 -0
- metadata +157 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: ca12b822901c77c6d973ab24876975f2983913ca7846b6139e7d115dba569ca7
|
4
|
+
data.tar.gz: 30129041c8c71063ddd5f91114edfd21e8f4bcb67d869c3c300d1e47eb29a710
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: a06e509346ab2682a527e540423799cfc9e19043376800643af00884e5e6ad9f9b460d983d2a3e9ca4c4407debefeb4fbd15ea7c696c4085a8f6184a1000a464
|
7
|
+
data.tar.gz: 49d0aa5b51d09290651cf1ad25d146d386706d5566017207af93d0bf3c332e8ab0c254cfa51cdd0fc9170a35721bc9ff9773b21d1d71692260235ca25f119601
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.travis.yml
ADDED
data/CODE_OF_CONDUCT.md
ADDED
@@ -0,0 +1,74 @@
|
|
1
|
+
# Contributor Covenant Code of Conduct
|
2
|
+
|
3
|
+
## Our Pledge
|
4
|
+
|
5
|
+
In the interest of fostering an open and welcoming environment, we as
|
6
|
+
contributors and maintainers pledge to making participation in our project and
|
7
|
+
our community a harassment-free experience for everyone, regardless of age, body
|
8
|
+
size, disability, ethnicity, gender identity and expression, level of experience,
|
9
|
+
nationality, personal appearance, race, religion, or sexual identity and
|
10
|
+
orientation.
|
11
|
+
|
12
|
+
## Our Standards
|
13
|
+
|
14
|
+
Examples of behavior that contributes to creating a positive environment
|
15
|
+
include:
|
16
|
+
|
17
|
+
* Using welcoming and inclusive language
|
18
|
+
* Being respectful of differing viewpoints and experiences
|
19
|
+
* Gracefully accepting constructive criticism
|
20
|
+
* Focusing on what is best for the community
|
21
|
+
* Showing empathy towards other community members
|
22
|
+
|
23
|
+
Examples of unacceptable behavior by participants include:
|
24
|
+
|
25
|
+
* The use of sexualized language or imagery and unwelcome sexual attention or
|
26
|
+
advances
|
27
|
+
* Trolling, insulting/derogatory comments, and personal or political attacks
|
28
|
+
* Public or private harassment
|
29
|
+
* Publishing others' private information, such as a physical or electronic
|
30
|
+
address, without explicit permission
|
31
|
+
* Other conduct which could reasonably be considered inappropriate in a
|
32
|
+
professional setting
|
33
|
+
|
34
|
+
## Our Responsibilities
|
35
|
+
|
36
|
+
Project maintainers are responsible for clarifying the standards of acceptable
|
37
|
+
behavior and are expected to take appropriate and fair corrective action in
|
38
|
+
response to any instances of unacceptable behavior.
|
39
|
+
|
40
|
+
Project maintainers have the right and responsibility to remove, edit, or
|
41
|
+
reject comments, commits, code, wiki edits, issues, and other contributions
|
42
|
+
that are not aligned to this Code of Conduct, or to ban temporarily or
|
43
|
+
permanently any contributor for other behaviors that they deem inappropriate,
|
44
|
+
threatening, offensive, or harmful.
|
45
|
+
|
46
|
+
## Scope
|
47
|
+
|
48
|
+
This Code of Conduct applies both within project spaces and in public spaces
|
49
|
+
when an individual is representing the project or its community. Examples of
|
50
|
+
representing a project or community include using an official project e-mail
|
51
|
+
address, posting via an official social media account, or acting as an appointed
|
52
|
+
representative at an online or offline event. Representation of a project may be
|
53
|
+
further defined and clarified by project maintainers.
|
54
|
+
|
55
|
+
## Enforcement
|
56
|
+
|
57
|
+
Instances of abusive, harassing, or otherwise unacceptable behavior may be
|
58
|
+
reported by contacting the project team at phuonglh0420@gmail.com. All
|
59
|
+
complaints will be reviewed and investigated and will result in a response that
|
60
|
+
is deemed necessary and appropriate to the circumstances. The project team is
|
61
|
+
obligated to maintain confidentiality with regard to the reporter of an incident.
|
62
|
+
Further details of specific enforcement policies may be posted separately.
|
63
|
+
|
64
|
+
Project maintainers who do not follow or enforce the Code of Conduct in good
|
65
|
+
faith may face temporary or permanent repercussions as determined by other
|
66
|
+
members of the project's leadership.
|
67
|
+
|
68
|
+
## Attribution
|
69
|
+
|
70
|
+
This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
|
71
|
+
available at [http://contributor-covenant.org/version/1/4][version]
|
72
|
+
|
73
|
+
[homepage]: http://contributor-covenant.org
|
74
|
+
[version]: http://contributor-covenant.org/version/1/4/
|
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,107 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
devise-fireauth (0.0.1.pre.alpha.1)
|
5
|
+
activesupport (>= 4)
|
6
|
+
devise (~> 4.0)
|
7
|
+
dry-configurable
|
8
|
+
httparty
|
9
|
+
|
10
|
+
GEM
|
11
|
+
remote: https://rubygems.org/
|
12
|
+
specs:
|
13
|
+
actionpack (5.2.1)
|
14
|
+
actionview (= 5.2.1)
|
15
|
+
activesupport (= 5.2.1)
|
16
|
+
rack (~> 2.0)
|
17
|
+
rack-test (>= 0.6.3)
|
18
|
+
rails-dom-testing (~> 2.0)
|
19
|
+
rails-html-sanitizer (~> 1.0, >= 1.0.2)
|
20
|
+
actionview (5.2.1)
|
21
|
+
activesupport (= 5.2.1)
|
22
|
+
builder (~> 3.1)
|
23
|
+
erubi (~> 1.4)
|
24
|
+
rails-dom-testing (~> 2.0)
|
25
|
+
rails-html-sanitizer (~> 1.0, >= 1.0.3)
|
26
|
+
activesupport (5.2.1)
|
27
|
+
concurrent-ruby (~> 1.0, >= 1.0.2)
|
28
|
+
i18n (>= 0.7, < 2)
|
29
|
+
minitest (~> 5.1)
|
30
|
+
tzinfo (~> 1.1)
|
31
|
+
bcrypt (3.1.12)
|
32
|
+
builder (3.2.3)
|
33
|
+
concurrent-ruby (1.0.5)
|
34
|
+
crass (1.0.4)
|
35
|
+
devise (4.5.0)
|
36
|
+
bcrypt (~> 3.0)
|
37
|
+
orm_adapter (~> 0.1)
|
38
|
+
railties (>= 4.1.0, < 6.0)
|
39
|
+
responders
|
40
|
+
warden (~> 1.2.3)
|
41
|
+
diff-lcs (1.3)
|
42
|
+
dry-configurable (0.7.0)
|
43
|
+
concurrent-ruby (~> 1.0)
|
44
|
+
erubi (1.7.1)
|
45
|
+
httparty (0.16.2)
|
46
|
+
multi_xml (>= 0.5.2)
|
47
|
+
i18n (1.1.0)
|
48
|
+
concurrent-ruby (~> 1.0)
|
49
|
+
loofah (2.2.2)
|
50
|
+
crass (~> 1.0.2)
|
51
|
+
nokogiri (>= 1.5.9)
|
52
|
+
method_source (0.9.0)
|
53
|
+
mini_portile2 (2.3.0)
|
54
|
+
minitest (5.11.3)
|
55
|
+
multi_xml (0.6.0)
|
56
|
+
nokogiri (1.8.4)
|
57
|
+
mini_portile2 (~> 2.3.0)
|
58
|
+
orm_adapter (0.5.0)
|
59
|
+
rack (2.0.5)
|
60
|
+
rack-test (1.1.0)
|
61
|
+
rack (>= 1.0, < 3)
|
62
|
+
rails-dom-testing (2.0.3)
|
63
|
+
activesupport (>= 4.2.0)
|
64
|
+
nokogiri (>= 1.6)
|
65
|
+
rails-html-sanitizer (1.0.4)
|
66
|
+
loofah (~> 2.2, >= 2.2.2)
|
67
|
+
railties (5.2.1)
|
68
|
+
actionpack (= 5.2.1)
|
69
|
+
activesupport (= 5.2.1)
|
70
|
+
method_source
|
71
|
+
rake (>= 0.8.7)
|
72
|
+
thor (>= 0.19.0, < 2.0)
|
73
|
+
rake (10.5.0)
|
74
|
+
responders (2.4.0)
|
75
|
+
actionpack (>= 4.2.0, < 5.3)
|
76
|
+
railties (>= 4.2.0, < 5.3)
|
77
|
+
rspec (3.8.0)
|
78
|
+
rspec-core (~> 3.8.0)
|
79
|
+
rspec-expectations (~> 3.8.0)
|
80
|
+
rspec-mocks (~> 3.8.0)
|
81
|
+
rspec-core (3.8.0)
|
82
|
+
rspec-support (~> 3.8.0)
|
83
|
+
rspec-expectations (3.8.1)
|
84
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
85
|
+
rspec-support (~> 3.8.0)
|
86
|
+
rspec-mocks (3.8.0)
|
87
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
88
|
+
rspec-support (~> 3.8.0)
|
89
|
+
rspec-support (3.8.0)
|
90
|
+
thor (0.20.0)
|
91
|
+
thread_safe (0.3.6)
|
92
|
+
tzinfo (1.2.5)
|
93
|
+
thread_safe (~> 0.1)
|
94
|
+
warden (1.2.7)
|
95
|
+
rack (>= 1.0)
|
96
|
+
|
97
|
+
PLATFORMS
|
98
|
+
ruby
|
99
|
+
|
100
|
+
DEPENDENCIES
|
101
|
+
bundler (~> 1.16)
|
102
|
+
devise-fireauth!
|
103
|
+
rake (~> 10.0)
|
104
|
+
rspec (~> 3.0)
|
105
|
+
|
106
|
+
BUNDLED WITH
|
107
|
+
1.16.4
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2018 [Phuong Le](mailto:phuonglh0420@gmail.com)
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,76 @@
|
|
1
|
+
# Devise Firebase authentication
|
2
|
+
|
3
|
+
A strategy to use Google Firebase as the authentication service behind the already famous authentication solution: [devise](https://github.com/plataformatec/devise)
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
```ruby
|
10
|
+
gem "devise-fireauth"
|
11
|
+
```
|
12
|
+
|
13
|
+
And then execute:
|
14
|
+
```bash
|
15
|
+
$ bundle install
|
16
|
+
```
|
17
|
+
|
18
|
+
## Usage
|
19
|
+
|
20
|
+
- Get your Firebse's Web API Key, then add a configuration section into the devise's initializer
|
21
|
+
```ruby
|
22
|
+
# config/initializers/devise.rb
|
23
|
+
Devise.setup do |config|
|
24
|
+
# Other configuration
|
25
|
+
config.authentication_keys = [
|
26
|
+
# Other keys, ex: email
|
27
|
+
:id_token
|
28
|
+
]
|
29
|
+
config.strip_whitespace_keys = [
|
30
|
+
# Other keys, ex: email
|
31
|
+
:id_token
|
32
|
+
]
|
33
|
+
config.fireauth do |f|
|
34
|
+
f.api_key = "YoUR-weB-aPi-KEy"
|
35
|
+
f.token_key = :id_token
|
36
|
+
end
|
37
|
+
end
|
38
|
+
```
|
39
|
+
- Modify your `User` model
|
40
|
+
- Use `firebase_authenticatable` strategy for devise
|
41
|
+
- Implement a class method `User.from_firebase` to find the corresponding user from your system. Example
|
42
|
+
```ruby
|
43
|
+
# app/models/user.rb
|
44
|
+
class User < ApplicationRecord
|
45
|
+
devise :firebase_authenticatable
|
46
|
+
class << self
|
47
|
+
def from_firebase(auth_hash)
|
48
|
+
# Find or create new user with auth_hash["email"]
|
49
|
+
# Update user name with auth_hash["displayName"]
|
50
|
+
# Return a user to allow login, or nil to reject
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
54
|
+
```
|
55
|
+
|
56
|
+
- Restart the server
|
57
|
+
- From now on, you can authenticate with the API via firebase `idToken`
|
58
|
+
- There is a full example of how to get firebase `idToken` and use it to authenticate with API lives in [spec/dummy/app/views/devise/sessions/new.html.haml](https://github.com/yeuem1vannam/devise-fireauth/blob/7bf5276b7b319fc6a5015cac597cd0aa708da3d7/spec/dummy/app/views/devise/sessions/new.html.haml#L32-L38)
|
59
|
+
|
60
|
+
## Development
|
61
|
+
|
62
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
63
|
+
|
64
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
65
|
+
|
66
|
+
## Contributing
|
67
|
+
|
68
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/yeuem1vannam/devise-fireauth. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
|
69
|
+
|
70
|
+
## License
|
71
|
+
|
72
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
73
|
+
|
74
|
+
## Code of Conduct
|
75
|
+
|
76
|
+
Everyone interacting in the `devise-fireauth` project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/yeuem1vannam/devise-fireauth/blob/master/CODE_OF_CONDUCT.md).
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "devise/fireauth"
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require "irb"
|
14
|
+
IRB.start(__FILE__)
|
data/bin/setup
ADDED
@@ -0,0 +1,33 @@
|
|
1
|
+
|
2
|
+
lib = File.expand_path("../lib", __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require "devise/fireauth/version"
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "devise-fireauth"
|
8
|
+
spec.version = Devise::Fireauth::VERSION
|
9
|
+
spec.authors = ["yeuem1vannam"]
|
10
|
+
|
11
|
+
spec.summary = %q{Firebase as authentication service}
|
12
|
+
spec.description = %q{Firebase as authentication service behind the devise}
|
13
|
+
spec.homepage = "https://github.com/yeuem1vannam/devise-fireauth"
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
# Specify which files should be added to the gem when it is released.
|
17
|
+
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
18
|
+
spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
|
19
|
+
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
20
|
+
end
|
21
|
+
spec.bindir = "exe"
|
22
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
23
|
+
spec.require_paths = ["lib"]
|
24
|
+
|
25
|
+
spec.add_dependency "devise", "~> 4.0"
|
26
|
+
spec.add_dependency "activesupport", ">= 4"
|
27
|
+
spec.add_dependency "dry-configurable"
|
28
|
+
spec.add_dependency "httparty"
|
29
|
+
|
30
|
+
spec.add_development_dependency "bundler", "~> 1.16"
|
31
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
32
|
+
spec.add_development_dependency "rspec", "~> 3.0"
|
33
|
+
end
|
@@ -0,0 +1,89 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
require "active_support/concern"
|
3
|
+
require "httparty"
|
4
|
+
|
5
|
+
module Devise
|
6
|
+
module Models
|
7
|
+
module FirebaseAuthenticatable
|
8
|
+
extend ActiveSupport::Concern
|
9
|
+
|
10
|
+
included do
|
11
|
+
attr_accessor Fireauth.token_key
|
12
|
+
end
|
13
|
+
|
14
|
+
module ClassMethods
|
15
|
+
FIREBASE_USER_INFO_URL = "https://www.googleapis.com/identitytoolkit/v3/relyingparty/getAccountInfo?key=#{Fireauth.api_key}"
|
16
|
+
####################################
|
17
|
+
# Overriden methods from Devise::Models::Authenticatable
|
18
|
+
####################################
|
19
|
+
|
20
|
+
#
|
21
|
+
# This method is called from:
|
22
|
+
# Warden::SessionSerializer in devise
|
23
|
+
#
|
24
|
+
# It takes as many params as elements had the array
|
25
|
+
# returned in serialize_into_session
|
26
|
+
#
|
27
|
+
# Recreates a resource from session data
|
28
|
+
#
|
29
|
+
def serialize_from_session(id)
|
30
|
+
resource = self.new
|
31
|
+
resource.id = id
|
32
|
+
resource
|
33
|
+
end
|
34
|
+
|
35
|
+
#
|
36
|
+
# Here you have to return and array with the data of your resource
|
37
|
+
# that you want to serialize into the session
|
38
|
+
#
|
39
|
+
# You might want to include some authentication data
|
40
|
+
#
|
41
|
+
def serialize_into_session(record)
|
42
|
+
[record.id]
|
43
|
+
end
|
44
|
+
|
45
|
+
#
|
46
|
+
# Here you do the request to the external webservice
|
47
|
+
#
|
48
|
+
# If the authentication is successful you should return
|
49
|
+
# a resource instance
|
50
|
+
#
|
51
|
+
# If the authentication fails you should return false
|
52
|
+
#
|
53
|
+
def firebase_authentication(auth_params)
|
54
|
+
auth_hash = firebase_verification(auth_params[Fireauth.token_key])
|
55
|
+
return nil if auth_hash.empty?
|
56
|
+
unless defined? self.from_firebase
|
57
|
+
raise NotImplementedError,
|
58
|
+
"#{self.name} model must implement class method `from_firebase'"
|
59
|
+
end
|
60
|
+
# Create new user here and return user
|
61
|
+
self.from_firebase(auth_hash)
|
62
|
+
end
|
63
|
+
|
64
|
+
private
|
65
|
+
|
66
|
+
# TODO:
|
67
|
+
# Verify the correct token
|
68
|
+
# https://firebase.google.com/docs/auth/admin/verify-id-tokens#retrieve_id_tokens_on_clients
|
69
|
+
def firebase_verification(id_token)
|
70
|
+
firebase_verification_call = HTTParty.post(
|
71
|
+
FIREBASE_USER_INFO_URL,
|
72
|
+
headers: {
|
73
|
+
'Content-Type': 'application/json'
|
74
|
+
},
|
75
|
+
body: {
|
76
|
+
'idToken': id_token
|
77
|
+
}.to_json
|
78
|
+
)
|
79
|
+
if firebase_verification_call.response.code == "200"
|
80
|
+
firebase_infos = firebase_verification_call.parsed_response
|
81
|
+
firebase_infos["users"][0]
|
82
|
+
else
|
83
|
+
{}
|
84
|
+
end
|
85
|
+
end
|
86
|
+
end
|
87
|
+
end
|
88
|
+
end
|
89
|
+
end
|
@@ -0,0 +1,40 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Devise
|
4
|
+
module Strategies
|
5
|
+
class FirebaseAuthenticatable < Authenticatable
|
6
|
+
#
|
7
|
+
# For an example check : https://github.com/plataformatec/devise/blob/master/lib/devise/strategies/database_authenticatable.rb
|
8
|
+
#
|
9
|
+
# Method called by warden to authenticate a resource.
|
10
|
+
#
|
11
|
+
def authenticate!
|
12
|
+
#
|
13
|
+
# authentication_hash doesn't include the password
|
14
|
+
#
|
15
|
+
auth_params = authentication_hash
|
16
|
+
return fail! unless auth_params[Fireauth.token_key]
|
17
|
+
|
18
|
+
#
|
19
|
+
# mapping.to is a wrapper over the resource model
|
20
|
+
#
|
21
|
+
# Treat the password as idToken
|
22
|
+
resource = mapping.to.firebase_authentication(auth_params)
|
23
|
+
|
24
|
+
return fail! unless resource
|
25
|
+
|
26
|
+
# remote_authentication method is defined in Devise::Models::RemoteAuthenticatable
|
27
|
+
#
|
28
|
+
# validate is a method defined in Devise::Strategies::Authenticatable. It takes
|
29
|
+
#a block which must return a boolean value.
|
30
|
+
#
|
31
|
+
# If the block returns true the resource will be loged in
|
32
|
+
# If the block returns false the authentication will fail!
|
33
|
+
#
|
34
|
+
if validate(resource)
|
35
|
+
success!(resource)
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
@@ -0,0 +1,42 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
require "devise"
|
3
|
+
require "dry-configurable"
|
4
|
+
require "devise/fireauth/version"
|
5
|
+
|
6
|
+
module Devise
|
7
|
+
def self.fireauth
|
8
|
+
yield(Devise::Fireauth.config)
|
9
|
+
end
|
10
|
+
|
11
|
+
warden do |manager|
|
12
|
+
manager.strategies.add(:firebase_authenticatable, Devise::Strategies::FirebaseAuthenticatable)
|
13
|
+
manager.default_strategies(scope: :user).unshift :firebase_authenticatable
|
14
|
+
end
|
15
|
+
add_module :firebase_authenticatable, controller: :sessions, route: { session: :routes }
|
16
|
+
|
17
|
+
module Fireauth
|
18
|
+
extend Dry::Configurable
|
19
|
+
|
20
|
+
setting :api_key, reader: true
|
21
|
+
setting :token_key, :id_token, reader: true
|
22
|
+
# TODO
|
23
|
+
# - project_id: for verifying aud / iss
|
24
|
+
end
|
25
|
+
|
26
|
+
# Those modules must be loaded after Fireauth configuration done
|
27
|
+
module Models
|
28
|
+
autoload :FirebaseAuthenticatable,
|
29
|
+
"devise/fireauth/models/firebase_authenticatable"
|
30
|
+
end
|
31
|
+
|
32
|
+
module Strategies
|
33
|
+
autoload :FirebaseAuthenticatable,
|
34
|
+
"devise/fireauth/strategies/firebase_authenticatable"
|
35
|
+
end
|
36
|
+
|
37
|
+
# TODO: verify the correct way to add strategies to warden
|
38
|
+
warden do |manager|
|
39
|
+
manager.strategies.add(:firebase_authenticatable, Devise::Strategies::FirebaseAuthenticatable)
|
40
|
+
end
|
41
|
+
add_module :firebase_authenticatable, controller: :sessions, route: { session: :routes }
|
42
|
+
end
|
metadata
ADDED
@@ -0,0 +1,157 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: devise-fireauth
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1.pre.alpha.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- yeuem1vannam
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2018-09-15 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: devise
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '4.0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '4.0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: activesupport
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '4'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '4'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: dry-configurable
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :runtime
|
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: httparty
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :runtime
|
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: bundler
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '1.16'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '1.16'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: rake
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - "~>"
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '10.0'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - "~>"
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '10.0'
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: rspec
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - "~>"
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '3.0'
|
104
|
+
type: :development
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - "~>"
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '3.0'
|
111
|
+
description: Firebase as authentication service behind the devise
|
112
|
+
email:
|
113
|
+
executables: []
|
114
|
+
extensions: []
|
115
|
+
extra_rdoc_files: []
|
116
|
+
files:
|
117
|
+
- ".gitignore"
|
118
|
+
- ".rspec"
|
119
|
+
- ".travis.yml"
|
120
|
+
- CODE_OF_CONDUCT.md
|
121
|
+
- Gemfile
|
122
|
+
- Gemfile.lock
|
123
|
+
- LICENSE.txt
|
124
|
+
- README.md
|
125
|
+
- Rakefile
|
126
|
+
- bin/console
|
127
|
+
- bin/setup
|
128
|
+
- devise-fireauth.gemspec
|
129
|
+
- lib/devise/fireauth.rb
|
130
|
+
- lib/devise/fireauth/models/firebase_authenticatable.rb
|
131
|
+
- lib/devise/fireauth/strategies/firebase_authenticatable.rb
|
132
|
+
- lib/devise/fireauth/version.rb
|
133
|
+
homepage: https://github.com/yeuem1vannam/devise-fireauth
|
134
|
+
licenses:
|
135
|
+
- MIT
|
136
|
+
metadata: {}
|
137
|
+
post_install_message:
|
138
|
+
rdoc_options: []
|
139
|
+
require_paths:
|
140
|
+
- lib
|
141
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
142
|
+
requirements:
|
143
|
+
- - ">="
|
144
|
+
- !ruby/object:Gem::Version
|
145
|
+
version: '0'
|
146
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
147
|
+
requirements:
|
148
|
+
- - ">"
|
149
|
+
- !ruby/object:Gem::Version
|
150
|
+
version: 1.3.1
|
151
|
+
requirements: []
|
152
|
+
rubyforge_project:
|
153
|
+
rubygems_version: 2.7.6
|
154
|
+
signing_key:
|
155
|
+
specification_version: 4
|
156
|
+
summary: Firebase as authentication service
|
157
|
+
test_files: []
|