fireauth 0.1.0

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.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 69db89de7b7f0021f1fca7a529c1a6584f591fa12644252c521c233efcad679e
4
+ data.tar.gz: 65eea3640514591b2b83806aede60a8c11fba36d906fc48781bfd5dc20f50eba
5
+ SHA512:
6
+ metadata.gz: 10044a6cbfbd847bf2de086f28a979985ab9197fdf79bffede775b1a2894262ce537ffeb600b74698eeabc0cb9516845e753716f76f92922cbcf868ad953e66f
7
+ data.tar.gz: 79c8a81fde73e80f862dafb11f41ae49354f67157cb35c623f1c485e770a138db5904681fd7fbfbc747a5fb157d04cce1850cfd83926c70b0d28baa29e804fe9
@@ -0,0 +1,45 @@
1
+ name: CI
2
+
3
+ on: [push]
4
+
5
+ jobs:
6
+ build:
7
+ runs-on: ubuntu-18.04
8
+ steps:
9
+ - uses: actions/checkout@v2
10
+ - uses: actions/cache@v1
11
+ id: cache
12
+ with:
13
+ path: ~/local/rubies
14
+ key: ruby-3.0.0
15
+ restore-keys: |
16
+ ruby-3.0.0
17
+ - uses: ruby/setup-ruby@v1
18
+ id: ruby
19
+ with:
20
+ ruby-version: 3.0.0
21
+ bundler-cache: true
22
+
23
+ - name: install bundler
24
+ run: gem install bundler
25
+
26
+ - name: Install dependent libralies
27
+ run: sudo apt-get install libpq-dev
28
+
29
+ - name: Cache gems
30
+ uses: actions/cache@preview
31
+ with:
32
+ path: vendor/bundle
33
+ key: ${{ runner.os }}-gem-${{ hashFiles('**/Gemfile.lock') }}
34
+ restore-keys: |
35
+ ${{ runner.os }}-gem-
36
+
37
+ - name: Bundle install
38
+ run: bundle install --jobs 4 --retry 3
39
+
40
+ # - name: Run Rubocop
41
+ # run: |
42
+ # bundle exec rubocop
43
+
44
+ - name: Run rspec
45
+ run: bundle exec rspec
@@ -0,0 +1,9 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
9
+ /vendor/
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
@@ -0,0 +1,7 @@
1
+ example_id | status | run_time |
2
+ ------------------------------------------------- | ------ | --------------- |
3
+ ./spec/fireauth/authentication_spec.rb[1:1:1:1:1] | passed | 0.01406 seconds |
4
+ ./spec/fireauth/authentication_spec.rb[1:1:2:1:1] | passed | 0.00593 seconds |
5
+ ./spec/fireauth/authentication_spec.rb[1:1:2:2:1] | passed | 0.00182 seconds |
6
+ ./spec/fireauth/configuration_spec.rb[1:1:1] | passed | 0.00008 seconds |
7
+ ./spec/fireauth/configuration_spec.rb[1:2:1] | passed | 0.00007 seconds |
@@ -0,0 +1 @@
1
+ 3.0.0
data/Gemfile ADDED
@@ -0,0 +1,9 @@
1
+ source "https://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in fireauth.gemspec
4
+ gemspec
5
+
6
+ gem "rake", "~> 12.0"
7
+ gem "faraday", "~> 1.0"
8
+ gem "rspec", "~> 3.0"
9
+ gem "webmock", "~> 3.0"
@@ -0,0 +1,54 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ fireauth (0.1.0)
5
+
6
+ GEM
7
+ remote: https://rubygems.org/
8
+ specs:
9
+ addressable (2.7.0)
10
+ public_suffix (>= 2.0.2, < 5.0)
11
+ crack (0.4.5)
12
+ rexml
13
+ diff-lcs (1.4.4)
14
+ faraday (1.3.0)
15
+ faraday-net_http (~> 1.0)
16
+ multipart-post (>= 1.2, < 3)
17
+ ruby2_keywords
18
+ faraday-net_http (1.0.1)
19
+ hashdiff (1.0.1)
20
+ multipart-post (2.1.1)
21
+ public_suffix (4.0.6)
22
+ rake (12.3.3)
23
+ rexml (3.2.4)
24
+ rspec (3.10.0)
25
+ rspec-core (~> 3.10.0)
26
+ rspec-expectations (~> 3.10.0)
27
+ rspec-mocks (~> 3.10.0)
28
+ rspec-core (3.10.1)
29
+ rspec-support (~> 3.10.0)
30
+ rspec-expectations (3.10.1)
31
+ diff-lcs (>= 1.2.0, < 2.0)
32
+ rspec-support (~> 3.10.0)
33
+ rspec-mocks (3.10.1)
34
+ diff-lcs (>= 1.2.0, < 2.0)
35
+ rspec-support (~> 3.10.0)
36
+ rspec-support (3.10.1)
37
+ ruby2_keywords (0.0.4)
38
+ webmock (3.11.1)
39
+ addressable (>= 2.3.6)
40
+ crack (>= 0.3.2)
41
+ hashdiff (>= 0.4.0, < 2.0.0)
42
+
43
+ PLATFORMS
44
+ ruby
45
+
46
+ DEPENDENCIES
47
+ faraday (~> 1.0)
48
+ fireauth!
49
+ rake (~> 12.0)
50
+ rspec (~> 3.0)
51
+ webmock (~> 3.0)
52
+
53
+ BUNDLED WITH
54
+ 2.2.3
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2021 yuta17
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.
@@ -0,0 +1,109 @@
1
+ # Fireauth
2
+
3
+ Simple Firebase Authentication for Ruby.
4
+
5
+ The source of the idea is [this article](https://medium.com/@Mpierrax/firebase-authentification-with-ruby-on-rails-backend-a9f7afc4d715).
6
+
7
+ This gem takes the idToken issued by Firebase and sends the request to identitytoolkit.
8
+
9
+ And it will return the authenticated user's information.
10
+
11
+ ## Installation
12
+
13
+ Add this line to your application's Gemfile:
14
+
15
+ ```ruby
16
+ gem 'fireauth'
17
+ ```
18
+
19
+ And then execute:
20
+
21
+ $ bundle install
22
+
23
+ Or install it yourself as:
24
+
25
+ $ gem install fireauth
26
+
27
+ ## Configuration
28
+
29
+ t's needed to set up your Firebase API Key.
30
+
31
+ If you are using Rails, this should probably go into config/initializers/fireauth.rb.
32
+
33
+ ```ruby
34
+ Fireauth.configure do |config|
35
+ config.firebase_api_key = ENV['FIREBASE_API_KEY']
36
+ end
37
+ ```
38
+
39
+ ## Usage
40
+
41
+ ```ruby
42
+ response = Fireauth::Authentication.call(id_token)
43
+ raise response['error']['message'] if response['error'].present?
44
+
45
+ authenticated_user = response['users'].first
46
+ ```
47
+
48
+ ### Payload Structure
49
+
50
+ A example of the payload structure from a Facebook login in JSON.
51
+
52
+ ```json
53
+ {
54
+ "kind": "identitytoolkit#GetAccountInfoResponse",
55
+ "users": [
56
+ {
57
+ "localId": "dummyLocalId",
58
+ "displayName": "dummyDisplayName",
59
+ "photoUrl": "https://example.com/picture",
60
+ "providerUserInfo": [
61
+ {
62
+ "providerId": "facebook.com",
63
+ "displayName": "dummyDisplayName",
64
+ "photoUrl": "https://example.com/picture",
65
+ "federatedId": "00000000",
66
+ "email": "dummy@example.com",
67
+ "rawId": "0000000000"
68
+ }
69
+ ],
70
+ "validSince": "1611130616",
71
+ "lastLoginAt": "1611375910133",
72
+ "createdAt": "1611130616888",
73
+ "lastRefreshAt": "2021-01-23T04:25:10.840Z"
74
+ }
75
+ ]
76
+ }
77
+ ```
78
+
79
+ Example for request with invalid id token.
80
+
81
+ ```json
82
+ {
83
+ "error": {
84
+ "code": 400,
85
+ "message": "INVALID_ID_TOKEN",
86
+ "errors": [
87
+ {
88
+ "domain": "global",
89
+ "message": "INVALID_ID_TOKEN",
90
+ "reason": "invalid"
91
+ }
92
+ ],
93
+ "status"
94
+ }
95
+ }
96
+ ```
97
+
98
+ ## Development
99
+
100
+ 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).
101
+
102
+ ## Contributing
103
+
104
+ Bug reports and pull requests are welcome on GitHub at https://github.com/yuta17/fireauth.
105
+
106
+
107
+ ## License
108
+
109
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
@@ -0,0 +1,2 @@
1
+ require "bundler/gem_tasks"
2
+ task :default => :spec
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "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__)
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,27 @@
1
+ require_relative 'lib/fireauth/version'
2
+
3
+ Gem::Specification.new do |spec|
4
+ spec.name = "fireauth"
5
+ spec.version = Fireauth::VERSION
6
+ spec.authors = ["yuta17"]
7
+ spec.email = ["usgitan@gmail.com"]
8
+
9
+ spec.summary = %q{Simple Firebase Authentication for Ruby.}
10
+ spec.description = %q{Simple Firebase Authentication for Ruby.}
11
+ spec.homepage = "https://github.com/yuta17/fireauth"
12
+ spec.license = "MIT"
13
+ spec.required_ruby_version = Gem::Requirement.new(">= 2.3.0")
14
+
15
+ spec.metadata["homepage_uri"] = spec.homepage
16
+ spec.metadata["source_code_uri"] = "https://github.com/yuta17/fireauth"
17
+ spec.metadata["changelog_uri"] = "https://github.com/yuta17/fireauth/CHANGELOG.md"
18
+
19
+ # Specify which files should be added to the gem when it is released.
20
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
21
+ spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
22
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
23
+ end
24
+ spec.bindir = "exe"
25
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
26
+ spec.require_paths = ["lib"]
27
+ end
@@ -0,0 +1,17 @@
1
+ require "fireauth/version"
2
+ require "fireauth/configuration"
3
+ require "fireauth/authentication"
4
+
5
+ module Fireauth
6
+ class << self
7
+ attr_writer :configuration
8
+ end
9
+
10
+ def self.configuration
11
+ @configuration ||= Configuration.new
12
+ end
13
+
14
+ def self.configure
15
+ yield configuration
16
+ end
17
+ end
@@ -0,0 +1,37 @@
1
+ require 'faraday'
2
+ require 'json'
3
+
4
+ module Fireauth
5
+ class Authentication
6
+ IDENTITY_URL = "https://www.googleapis.com/identitytoolkit/v3/relyingparty/getAccountInfo"
7
+
8
+ # @example
9
+ # response = Fireauth::Authentication.call(id_token)
10
+ #
11
+ # @param [String] id_token Firebase ID Token
12
+ # @return [Hash] authenticated user or error message
13
+ def self.call(id_token)
14
+ new(id_token).response
15
+ end
16
+
17
+ def initialize(id_token)
18
+ @id_token = id_token
19
+ @firebase_api_key = Fireauth.configuration.firebase_api_key
20
+ end
21
+
22
+ def response
23
+ JSON.parse(request.body)
24
+ end
25
+
26
+ private
27
+
28
+ attr_reader :id_token, :firebase_api_key
29
+
30
+ def request
31
+ url = "#{IDENTITY_URL}?key=#{firebase_api_key}"
32
+ request_body = "{ 'idToken': '#{id_token}' }"
33
+
34
+ Faraday.post(url, request_body, content_type: 'application/json')
35
+ end
36
+ end
37
+ end
@@ -0,0 +1,9 @@
1
+ module Fireauth
2
+ class Configuration
3
+ attr_accessor :firebase_api_key
4
+
5
+ def initialize
6
+ @firebase_api_key = ''
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,3 @@
1
+ module Fireauth
2
+ VERSION = "0.1.0"
3
+ end
metadata ADDED
@@ -0,0 +1,63 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: fireauth
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - yuta17
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2021-01-23 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: Simple Firebase Authentication for Ruby.
14
+ email:
15
+ - usgitan@gmail.com
16
+ executables: []
17
+ extensions: []
18
+ extra_rdoc_files: []
19
+ files:
20
+ - ".github/workflows/rspec.yml"
21
+ - ".gitignore"
22
+ - ".rspec"
23
+ - ".rspec_status"
24
+ - ".ruby-version"
25
+ - Gemfile
26
+ - Gemfile.lock
27
+ - LICENSE.txt
28
+ - README.md
29
+ - Rakefile
30
+ - bin/console
31
+ - bin/setup
32
+ - fireauth.gemspec
33
+ - lib/fireauth.rb
34
+ - lib/fireauth/authentication.rb
35
+ - lib/fireauth/configuration.rb
36
+ - lib/fireauth/version.rb
37
+ homepage: https://github.com/yuta17/fireauth
38
+ licenses:
39
+ - MIT
40
+ metadata:
41
+ homepage_uri: https://github.com/yuta17/fireauth
42
+ source_code_uri: https://github.com/yuta17/fireauth
43
+ changelog_uri: https://github.com/yuta17/fireauth/CHANGELOG.md
44
+ post_install_message:
45
+ rdoc_options: []
46
+ require_paths:
47
+ - lib
48
+ required_ruby_version: !ruby/object:Gem::Requirement
49
+ requirements:
50
+ - - ">="
51
+ - !ruby/object:Gem::Version
52
+ version: 2.3.0
53
+ required_rubygems_version: !ruby/object:Gem::Requirement
54
+ requirements:
55
+ - - ">="
56
+ - !ruby/object:Gem::Version
57
+ version: '0'
58
+ requirements: []
59
+ rubygems_version: 3.2.3
60
+ signing_key:
61
+ specification_version: 4
62
+ summary: Simple Firebase Authentication for Ruby.
63
+ test_files: []