firebase-auth-rails 0.0.4 → 0.1.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +120 -1
- data/lib/firebase/auth/rails/version.rb +1 -1
- data/lib/firebase/auth/token.rb +1 -3
- metadata +15 -16
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c353ae51e753adbb1e5b6a6b1d2edca946c7f2bb7e9c9919a48458a6d69f406c
|
4
|
+
data.tar.gz: 51a63c88ec83b863736fade086089717c3274771333722779572bdfdd73ff436
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e2f0f7714cc897055465ba21e61cf5d0eac57800bf25512f8542317593155f78e6d26837926d0e9068adb08d3420716db775735cf9c01aac8eed88bfe893ad57
|
7
|
+
data.tar.gz: c798b6cf2e797f0a6a6c0b6f64e0e563e584521388cfd76c094694764bd43a9d325e42d9be3974a7e88f72ef397df9adf1c0fb4a440f1f154d597896aebaa230
|
data/README.md
CHANGED
@@ -3,13 +3,100 @@
|
|
3
3
|
|
4
4
|
This is a plugin that performs firebase authentication in rails.
|
5
5
|
|
6
|
+
[![Gem Version](https://badge.fury.io/rb/firebase-auth-rails.svg)](https://badge.fury.io/rb/firebase-auth-rails)
|
7
|
+
[![Build Status](https://travis-ci.org/penguinwokrs/firebase-auth-rails.svg?branch=master)](https://travis-ci.org/penguinwokrs/firebase-auth-rails)
|
8
|
+
[![Maintainability](https://api.codeclimate.com/v1/badges/42c3a31a589213a5b82b/maintainability)](https://codeclimate.com/github/penguinwokrs/aws-transcoder-rails/maintainability)
|
9
|
+
|
10
|
+
Supported Rails version is 5.x, 6.0
|
11
|
+
|
12
|
+
As of version 4.2, the test environment is not ready and I do not know if it will work.
|
13
|
+
|
14
|
+
|
6
15
|
Made influenced by [firebase_id_token](https://github.com/fschuindt/firebase_id_token) and [knock](https://github.com/nsarno/knock)
|
7
16
|
|
8
17
|
Thanks to the author.
|
9
18
|
|
19
|
+
## Status
|
20
|
+
Now it's a beta version.
|
21
|
+
Only login feature is available.
|
22
|
+
It does not have firebase user creation feature.
|
10
23
|
|
11
24
|
## Usage
|
12
|
-
|
25
|
+
Add database migrate method.
|
26
|
+
|
27
|
+
```ruby
|
28
|
+
class AddUidToUsers < ActiveRecord::Migration[5.1]
|
29
|
+
def change
|
30
|
+
add_column :users, :uid, :string
|
31
|
+
end
|
32
|
+
end
|
33
|
+
```
|
34
|
+
|
35
|
+
Add the following code to the controller to use.
|
36
|
+
|
37
|
+
```ruby
|
38
|
+
include Firebase::Auth::Authenticable
|
39
|
+
before_action :authenticate_user
|
40
|
+
```
|
41
|
+
|
42
|
+
The current user is defined
|
43
|
+
``` ruby
|
44
|
+
current_user.user_name
|
45
|
+
# => yamada
|
46
|
+
```
|
47
|
+
|
48
|
+
The following is a generic user creation code
|
49
|
+
|
50
|
+
* api/v1/application_controller
|
51
|
+
|
52
|
+
```ruby
|
53
|
+
module Api
|
54
|
+
class V1::ApplicationController < ActionController::API
|
55
|
+
include Firebase::Auth::Authenticable
|
56
|
+
before_action :authenticate_user
|
57
|
+
end
|
58
|
+
end
|
59
|
+
```
|
60
|
+
|
61
|
+
* api/v1/auth/registrations_controller
|
62
|
+
```ruby
|
63
|
+
|
64
|
+
require_dependency 'api/v1/application_controller'
|
65
|
+
module Api
|
66
|
+
module V1
|
67
|
+
module Auth
|
68
|
+
class RegistrationsController < V1::ApplicationController
|
69
|
+
skip_before_action :authenticate_user
|
70
|
+
|
71
|
+
def create
|
72
|
+
raise ArgumentError, 'BadRequest Parameter' if payload.blank?
|
73
|
+
user = User.create!(sign_up_params.merge(uid: payload['sub']))
|
74
|
+
render json: user, serializer: V1::AuthSerializer, status: :ok
|
75
|
+
end
|
76
|
+
|
77
|
+
private
|
78
|
+
|
79
|
+
def sign_up_params
|
80
|
+
params.require(:registration).permit(:user_name, :display_name)
|
81
|
+
end
|
82
|
+
|
83
|
+
def token_from_request_headers
|
84
|
+
request.headers['Authorization']&.split&.last
|
85
|
+
end
|
86
|
+
|
87
|
+
def token
|
88
|
+
params[:token] || token_from_request_headers
|
89
|
+
end
|
90
|
+
|
91
|
+
def payload
|
92
|
+
@payload ||= FirebaseIdToken::Signature.verify token
|
93
|
+
end
|
94
|
+
end
|
95
|
+
end
|
96
|
+
end
|
97
|
+
end
|
98
|
+
|
99
|
+
```
|
13
100
|
|
14
101
|
## Installation
|
15
102
|
Add this line to your application's Gemfile:
|
@@ -28,8 +115,40 @@ Or install it yourself as:
|
|
28
115
|
$ gem install firebase-auth-rails
|
29
116
|
```
|
30
117
|
|
118
|
+
## initializer
|
119
|
+
```ruby
|
120
|
+
# frozen_string_literal: true
|
121
|
+
|
122
|
+
FirebaseIdToken.configure do |config|
|
123
|
+
config.redis = Redis.new
|
124
|
+
config.project_ids = ['firebase_project_id']
|
125
|
+
end
|
126
|
+
|
127
|
+
```
|
128
|
+
|
129
|
+
## Testing
|
130
|
+
There is preparation for testing firebase certification.
|
131
|
+
Please click here. [link](https://github.com/fschuindt/firebase_id_token#user-content-development)
|
132
|
+
|
31
133
|
## Contributing
|
134
|
+
We welcome PR.
|
135
|
+
|
136
|
+
|
137
|
+
## development
|
138
|
+
### getting started
|
139
|
+
|
140
|
+
* Test preparation
|
32
141
|
|
142
|
+
```bash
|
143
|
+
cd test/dummy/
|
144
|
+
bin/rails migrate
|
145
|
+
```
|
146
|
+
|
147
|
+
* The test is a minitest
|
148
|
+
```bash
|
149
|
+
# Project root dir
|
150
|
+
rake test
|
151
|
+
```
|
33
152
|
|
34
153
|
## License
|
35
154
|
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
data/lib/firebase/auth/token.rb
CHANGED
@@ -23,11 +23,9 @@ module Firebase
|
|
23
23
|
|
24
24
|
def set_public_key
|
25
25
|
# FIXME: cache
|
26
|
-
|
27
|
-
FirebaseIdToken::Certificates.request
|
26
|
+
FirebaseIdToken::Certificates.request! unless 60 <= FirebaseIdToken::Certificates.ttl
|
28
27
|
nil
|
29
28
|
end
|
30
|
-
|
31
29
|
end
|
32
30
|
end
|
33
31
|
end
|
metadata
CHANGED
@@ -1,29 +1,29 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: firebase-auth-rails
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.1.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- penguinwokrs
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2019-06-21 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: sqlite3
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- - "
|
17
|
+
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version:
|
19
|
+
version: 1.3.6
|
20
20
|
type: :development
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
|
-
- - "
|
24
|
+
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version:
|
26
|
+
version: 1.3.6
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: redis
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -84,36 +84,36 @@ dependencies:
|
|
84
84
|
name: rails
|
85
85
|
requirement: !ruby/object:Gem::Requirement
|
86
86
|
requirements:
|
87
|
-
- - "
|
87
|
+
- - ">="
|
88
88
|
- !ruby/object:Gem::Version
|
89
|
-
version:
|
89
|
+
version: '0'
|
90
90
|
type: :runtime
|
91
91
|
prerelease: false
|
92
92
|
version_requirements: !ruby/object:Gem::Requirement
|
93
93
|
requirements:
|
94
|
-
- - "
|
94
|
+
- - ">="
|
95
95
|
- !ruby/object:Gem::Version
|
96
|
-
version:
|
96
|
+
version: '0'
|
97
97
|
- !ruby/object:Gem::Dependency
|
98
98
|
name: firebase_id_token
|
99
99
|
requirement: !ruby/object:Gem::Requirement
|
100
100
|
requirements:
|
101
101
|
- - ">="
|
102
102
|
- !ruby/object:Gem::Version
|
103
|
-
version: 2.
|
103
|
+
version: 2.3.0
|
104
104
|
- - "~>"
|
105
105
|
- !ruby/object:Gem::Version
|
106
|
-
version: 2.3
|
106
|
+
version: '2.3'
|
107
107
|
type: :runtime
|
108
108
|
prerelease: false
|
109
109
|
version_requirements: !ruby/object:Gem::Requirement
|
110
110
|
requirements:
|
111
111
|
- - ">="
|
112
112
|
- !ruby/object:Gem::Version
|
113
|
-
version: 2.
|
113
|
+
version: 2.3.0
|
114
114
|
- - "~>"
|
115
115
|
- !ruby/object:Gem::Version
|
116
|
-
version: 2.3
|
116
|
+
version: '2.3'
|
117
117
|
- !ruby/object:Gem::Dependency
|
118
118
|
name: jwt
|
119
119
|
requirement: !ruby/object:Gem::Requirement
|
@@ -168,8 +168,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
168
168
|
- !ruby/object:Gem::Version
|
169
169
|
version: '0'
|
170
170
|
requirements: []
|
171
|
-
|
172
|
-
rubygems_version: 2.7.6
|
171
|
+
rubygems_version: 3.0.3
|
173
172
|
signing_key:
|
174
173
|
specification_version: 4
|
175
174
|
summary: Summary of Firebase::Auth::Rails.
|