authform-rails 0.2.1
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 +7 -0
- data/.gitignore +11 -0
- data/.rspec +3 -0
- data/.travis.yml +6 -0
- data/Gemfile +7 -0
- data/Gemfile.lock +38 -0
- data/LICENSE.md +21 -0
- data/README.md +56 -0
- data/Rakefile +6 -0
- data/authform-rails.gemspec +29 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/lib/authform/rails.rb +10 -0
- data/lib/authform/rails/concern.rb +46 -0
- data/lib/authform/rails/version.rb +5 -0
- metadata +74 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 6462259228c2158788d23a2e51801ba38daa7de0be0bbfe120ff0b6aa7747bcf
|
4
|
+
data.tar.gz: a0fc634b1451aeb1afaeea9076bbccf7263447341e07af52326629b2c490fd4c
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 64bb19fcfb3edb0c55c4c09b9e5844d53a6baec370523ca77fc47f0425d8dcb63f0442b15ece83e4c98c6c5d8d91e09a8a82ad48fbea12d4e25076bf1e43a1c0
|
7
|
+
data.tar.gz: 61520120617645201a4006f35cbba9b7eeed0afa591e817bc6308c2b56f80f7a91bb147d3755fc3251fa96f6be8d502ee9f7d145343e9c1186b0192bfdf5204b
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,38 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
authform-rails (0.2.1)
|
5
|
+
faraday
|
6
|
+
|
7
|
+
GEM
|
8
|
+
remote: https://rubygems.org/
|
9
|
+
specs:
|
10
|
+
diff-lcs (1.3)
|
11
|
+
faraday (1.0.0)
|
12
|
+
multipart-post (>= 1.2, < 3)
|
13
|
+
multipart-post (2.1.1)
|
14
|
+
rake (12.3.3)
|
15
|
+
rspec (3.9.0)
|
16
|
+
rspec-core (~> 3.9.0)
|
17
|
+
rspec-expectations (~> 3.9.0)
|
18
|
+
rspec-mocks (~> 3.9.0)
|
19
|
+
rspec-core (3.9.1)
|
20
|
+
rspec-support (~> 3.9.1)
|
21
|
+
rspec-expectations (3.9.0)
|
22
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
23
|
+
rspec-support (~> 3.9.0)
|
24
|
+
rspec-mocks (3.9.1)
|
25
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
26
|
+
rspec-support (~> 3.9.0)
|
27
|
+
rspec-support (3.9.2)
|
28
|
+
|
29
|
+
PLATFORMS
|
30
|
+
ruby
|
31
|
+
|
32
|
+
DEPENDENCIES
|
33
|
+
authform-rails!
|
34
|
+
rake (~> 12.0)
|
35
|
+
rspec (~> 3.0)
|
36
|
+
|
37
|
+
BUNDLED WITH
|
38
|
+
2.1.4
|
data/LICENSE.md
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2020 NM Digital LLC
|
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,56 @@
|
|
1
|
+
# Authform Rails
|
2
|
+
|
3
|
+
## Introduction
|
4
|
+
|
5
|
+
Add authentication to your Rails application - in 1 minute or less - with <a href="https://api.authform.io">Authform.io</a>.
|
6
|
+
|
7
|
+
## Installation
|
8
|
+
|
9
|
+
Add this line to your Rails application's Gemfile:
|
10
|
+
|
11
|
+
```ruby
|
12
|
+
gem "authform-rails"
|
13
|
+
```
|
14
|
+
|
15
|
+
And then execute:
|
16
|
+
|
17
|
+
```bash
|
18
|
+
$ bundle install
|
19
|
+
```
|
20
|
+
|
21
|
+
## Usage
|
22
|
+
|
23
|
+
Add your form
|
24
|
+
|
25
|
+
```html
|
26
|
+
<form action="https://api.authform.io/v1/f/{FORM_UUID}" method="POST">
|
27
|
+
<input type="email" name="email">
|
28
|
+
<button type="submit">Sign In</button>
|
29
|
+
</form>
|
30
|
+
```
|
31
|
+
|
32
|
+
Add the Authform::Rails::Concern to your ApplicationController.rb
|
33
|
+
|
34
|
+
```ruby
|
35
|
+
class ApplicationController < ActionController::Base
|
36
|
+
include Authform::Rails::Concern.new form_uuid: {FORM_UUID}
|
37
|
+
|
38
|
+
before_action :require_login
|
39
|
+
|
40
|
+
private
|
41
|
+
|
42
|
+
def require_login
|
43
|
+
unless current_user
|
44
|
+
flash[:error] = "You must be logged in to access this section"
|
45
|
+
|
46
|
+
redirect_to new_login_url # halts request cycle
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
```
|
51
|
+
|
52
|
+
That's it!
|
53
|
+
|
54
|
+
## License
|
55
|
+
|
56
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
data/Rakefile
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
require_relative "lib/authform/rails/version"
|
2
|
+
|
3
|
+
Gem::Specification.new do |spec|
|
4
|
+
spec.name = "authform-rails"
|
5
|
+
spec.version = Authform::Rails::VERSION
|
6
|
+
spec.authors = ["gatleon"]
|
7
|
+
spec.email = ["gatleon"]
|
8
|
+
|
9
|
+
spec.summary = %q{Summary}
|
10
|
+
spec.description = %q{Description}
|
11
|
+
spec.homepage = "https://github.com/gatleon"
|
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/gatleon/authform-rails"
|
17
|
+
spec.metadata["changelog_uri"] = "https://github.com/gatleon/authform-rails"
|
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
|
+
|
28
|
+
spec.add_runtime_dependency "faraday"
|
29
|
+
end
|
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "authform/rails"
|
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,46 @@
|
|
1
|
+
module Authform
|
2
|
+
module Rails
|
3
|
+
class Concern < Module
|
4
|
+
def initialize(form_uuid:)
|
5
|
+
super() do
|
6
|
+
extend ActiveSupport::Concern
|
7
|
+
|
8
|
+
included do
|
9
|
+
helper_method :current_user
|
10
|
+
before_action :_exchange_voucher_for_user
|
11
|
+
end
|
12
|
+
|
13
|
+
private
|
14
|
+
|
15
|
+
define_method :current_user do
|
16
|
+
begin
|
17
|
+
JSON.parse(cookies[authform_user_cookie_key])["data"]
|
18
|
+
rescue
|
19
|
+
nil
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
define_method :_exchange_voucher_for_user do
|
24
|
+
if params[:_authformVoucher]
|
25
|
+
response = Faraday.get("https://api.authform.io/v1/exchangeVoucherForUser.json", { formUuid: form_uuid, voucher: params[:_authformVoucher] })
|
26
|
+
|
27
|
+
if response.status == 200
|
28
|
+
cookies[authform_user_cookie_key] = response.body
|
29
|
+
end
|
30
|
+
|
31
|
+
q = Rack::Utils.parse_query(URI.parse(request.url).query)
|
32
|
+
q.delete("_authformVoucher")
|
33
|
+
url = q.empty? ? request.path : "#{request.path}?#{q.to_query}"
|
34
|
+
|
35
|
+
redirect_to url, status: 302 # redirect to finish removal of query param
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
define_method :authform_user_cookie_key do
|
40
|
+
"user#{form_uuid}"
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
metadata
ADDED
@@ -0,0 +1,74 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: authform-rails
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.2.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- gatleon
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2020-02-05 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: faraday
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
description: Description
|
28
|
+
email:
|
29
|
+
- gatleon
|
30
|
+
executables: []
|
31
|
+
extensions: []
|
32
|
+
extra_rdoc_files: []
|
33
|
+
files:
|
34
|
+
- ".gitignore"
|
35
|
+
- ".rspec"
|
36
|
+
- ".travis.yml"
|
37
|
+
- Gemfile
|
38
|
+
- Gemfile.lock
|
39
|
+
- LICENSE.md
|
40
|
+
- README.md
|
41
|
+
- Rakefile
|
42
|
+
- authform-rails.gemspec
|
43
|
+
- bin/console
|
44
|
+
- bin/setup
|
45
|
+
- lib/authform/rails.rb
|
46
|
+
- lib/authform/rails/concern.rb
|
47
|
+
- lib/authform/rails/version.rb
|
48
|
+
homepage: https://github.com/gatleon
|
49
|
+
licenses:
|
50
|
+
- MIT
|
51
|
+
metadata:
|
52
|
+
homepage_uri: https://github.com/gatleon
|
53
|
+
source_code_uri: https://github.com/gatleon/authform-rails
|
54
|
+
changelog_uri: https://github.com/gatleon/authform-rails
|
55
|
+
post_install_message:
|
56
|
+
rdoc_options: []
|
57
|
+
require_paths:
|
58
|
+
- lib
|
59
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
60
|
+
requirements:
|
61
|
+
- - ">="
|
62
|
+
- !ruby/object:Gem::Version
|
63
|
+
version: 2.3.0
|
64
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
requirements: []
|
70
|
+
rubygems_version: 3.0.3
|
71
|
+
signing_key:
|
72
|
+
specification_version: 4
|
73
|
+
summary: Summary
|
74
|
+
test_files: []
|