gatleon-authform-rails 0.1.0 → 0.5.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +1 -0
- data/.ruby-version +1 -0
- data/Gemfile +1 -0
- data/Gemfile.lock +5 -1
- data/README.md +22 -12
- data/gatleon-authform-rails.gemspec +2 -0
- data/lib/gatleon/authform/rails/concern.rb +18 -17
- data/lib/gatleon/authform/rails/user.rb +45 -7
- data/lib/gatleon/authform/rails/version.rb +1 -1
- metadata +18 -4
- data/gatleon-authform-rails.png +0 -0
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 685b07de50135a4e5370690768aa9d3c35ee9ec6d69067cb64bf8d7114a17e15
|
4
|
+
data.tar.gz: 4575c9167863052ef09dbf8485d9ae61d3d31a3ab6e398f5ff13f877e5b7da92
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0faeb596324770954d58d7561a6269e2564e0c87bc46f5929a97a6af553787a6e2dfa04be77c7502ee9c3d8e13f02f46efcc92d6cc3af9114e846e0aa80a0318
|
7
|
+
data.tar.gz: d468569f24c293468138382d51d6eafa44d219307c2586daadd266a9dd22d3657651b2c6256635cb7f897e04b02ff5cfbfc338af43578f81fe091d1dfc8d2458
|
data/.gitignore
CHANGED
data/.ruby-version
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
2.6.6
|
data/Gemfile
CHANGED
data/Gemfile.lock
CHANGED
@@ -1,7 +1,8 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
gatleon-authform-rails (0.
|
4
|
+
gatleon-authform-rails (0.5.0)
|
5
|
+
xxhash
|
5
6
|
|
6
7
|
GEM
|
7
8
|
remote: https://rubygems.org/
|
@@ -143,6 +144,8 @@ GEM
|
|
143
144
|
websocket-driver (0.7.1)
|
144
145
|
websocket-extensions (>= 0.1.0)
|
145
146
|
websocket-extensions (0.1.4)
|
147
|
+
xxhash (0.4.0)
|
148
|
+
yard (0.9.24)
|
146
149
|
zeitwerk (2.3.0)
|
147
150
|
|
148
151
|
PLATFORMS
|
@@ -154,6 +157,7 @@ DEPENDENCIES
|
|
154
157
|
rails
|
155
158
|
rake (~> 12.0)
|
156
159
|
rspec (~> 3.0)
|
160
|
+
yard
|
157
161
|
|
158
162
|
BUNDLED WITH
|
159
163
|
2.1.4
|
data/README.md
CHANGED
@@ -1,6 +1,4 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
# authform-rails by gatleon
|
1
|
+
# gatleon-authform-rails
|
4
2
|
|
5
3
|
add authentication to your application - in 1 minute or less.
|
6
4
|
|
@@ -18,14 +16,25 @@ and then execute:
|
|
18
16
|
$ bundle install
|
19
17
|
```
|
20
18
|
|
21
|
-
|
19
|
+
open rails credentials:
|
20
|
+
|
21
|
+
```
|
22
|
+
$ EDITOR=vim rails credentials:edit
|
23
|
+
```
|
24
|
+
|
25
|
+
set authform credentials:
|
26
|
+
|
27
|
+
```
|
28
|
+
authform:
|
29
|
+
public_key: "Available at https://authform.gatleon.com"
|
30
|
+
secret_key: "Available at https://authform.gatleon.com"
|
31
|
+
```
|
32
|
+
|
33
|
+
add a profile controller:
|
22
34
|
|
23
35
|
```ruby
|
24
36
|
class ProfileController < ActionController::Base
|
25
|
-
|
26
|
-
AUTHFORM_FORM_PUBLIC_KEY = "" # Available at https://authform.gatleon.com. coming soon!
|
27
|
-
|
28
|
-
include Gatleon::Authform::Rails::Concern.new(public_key: AUTHFORM_FORM_PUBLIC_KEY, secret_key: AUTHFORM_FORM_SECRET_KEY)
|
37
|
+
include Gatleon::Authform::Rails::Concern.new(Rails.application.credentials.dig(:authform))
|
29
38
|
|
30
39
|
before_action :require_login, only: [:index]
|
31
40
|
|
@@ -43,7 +52,8 @@ class ProfileController < ActionController::Base
|
|
43
52
|
erb = <<~ERB
|
44
53
|
<p style="color: red;"><%= flash[:error] %></p>
|
45
54
|
<h1>Sign In</h1>
|
46
|
-
<form action="https://authform.
|
55
|
+
<form action="https://api.authform.io/v1/form/<%= Rails.application.credentials.dig(:authform, :public_key) %>" method="POST">
|
56
|
+
<input type="hidden" name="successPath" value="/profile">
|
47
57
|
<input type="email" name="email">
|
48
58
|
<button type="submit">Sign In</button>
|
49
59
|
</form>
|
@@ -64,12 +74,12 @@ class ProfileController < ActionController::Base
|
|
64
74
|
end
|
65
75
|
```
|
66
76
|
|
67
|
-
add profile routes to routes.rb
|
77
|
+
add profile routes to routes.rb:
|
68
78
|
|
69
79
|
```ruby
|
70
80
|
Rails.application.routes.draw do
|
71
|
-
get
|
72
|
-
get
|
81
|
+
get "/profile", to: "profile#index", as: :profile
|
82
|
+
get "/profile/signin", to: "profile#signin", as: :profile_signin
|
73
83
|
end
|
74
84
|
```
|
75
85
|
|
@@ -1,11 +1,14 @@
|
|
1
|
+
require "xxhash"
|
2
|
+
|
1
3
|
module Gatleon
|
2
4
|
module Authform
|
3
5
|
module Rails
|
4
6
|
class Concern < Module
|
5
7
|
def initialize(public_key:,
|
6
8
|
secret_key:,
|
9
|
+
domain: nil,
|
7
10
|
current_user_method_name: "current_user",
|
8
|
-
_authform_base_url: "https://authform.
|
11
|
+
_authform_base_url: "https://api.authform.io")
|
9
12
|
super() do
|
10
13
|
extend ActiveSupport::Concern
|
11
14
|
|
@@ -19,9 +22,11 @@ module Gatleon
|
|
19
22
|
# defaults to current_user
|
20
23
|
define_method current_user_method_name do
|
21
24
|
begin
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
+
Gatleon::Authform::Rails::User.new(_cookies: cookies,
|
26
|
+
_authform_user_cookie_key: _authform_user_cookie_key,
|
27
|
+
_form_secret_key: secret_key,
|
28
|
+
_domain: domain,
|
29
|
+
_authform_base_url: _authform_base_url)
|
25
30
|
rescue
|
26
31
|
nil
|
27
32
|
end
|
@@ -34,18 +39,7 @@ module Gatleon
|
|
34
39
|
uri = URI("#{_authform_base_url}/v1/exchangeUserVoucherForUser/#{params[:_authformUserVoucher]}")
|
35
40
|
response = Net::HTTP.get_response(uri)
|
36
41
|
|
37
|
-
if response.code.to_i == 200
|
38
|
-
# First attempt WITHOUT all - for setting on platforms like heroku that deny setting cookies across all subdomains
|
39
|
-
cookies[_authform_user_cookie_key] = {
|
40
|
-
value: response.body
|
41
|
-
}
|
42
|
-
|
43
|
-
# Then set all - desired behavior for hosting your own domain
|
44
|
-
cookies[_authform_user_cookie_key] = {
|
45
|
-
value: response.body,
|
46
|
-
domain: :all
|
47
|
-
}
|
48
|
-
end
|
42
|
+
cookies[_authform_user_cookie_key] = _cookie_attrs(response.body) if response.code.to_i == 200
|
49
43
|
|
50
44
|
q = Rack::Utils.parse_query(URI.parse(request.url).query)
|
51
45
|
q.delete("_authformUserVoucher")
|
@@ -57,7 +51,14 @@ module Gatleon
|
|
57
51
|
end
|
58
52
|
|
59
53
|
define_method :_authform_user_cookie_key do
|
60
|
-
|
54
|
+
"#{public_key}_#{XXhash.xxh32(domain)}"
|
55
|
+
end
|
56
|
+
|
57
|
+
define_method :_cookie_attrs do |value|
|
58
|
+
{
|
59
|
+
value: value,
|
60
|
+
domain: domain
|
61
|
+
}.compact
|
61
62
|
end
|
62
63
|
end
|
63
64
|
end
|
@@ -1,30 +1,45 @@
|
|
1
|
+
require "json"
|
2
|
+
|
1
3
|
module Gatleon
|
2
4
|
module Authform
|
3
5
|
module Rails
|
4
6
|
class User
|
5
7
|
PERMITTED_CHARS = /\A[a-zA-Z0-9_)]*\z/
|
6
8
|
|
7
|
-
def initialize(
|
8
|
-
|
9
|
-
|
9
|
+
def initialize(_cookies:,
|
10
|
+
_authform_user_cookie_key:,
|
11
|
+
_form_secret_key:,
|
12
|
+
_domain:,
|
13
|
+
_authform_base_url:)
|
14
|
+
@_cookies = _cookies
|
15
|
+
@_authform_user_cookie_key = _authform_user_cookie_key
|
10
16
|
@_form_secret_key = _form_secret_key
|
17
|
+
@_domain = _domain
|
11
18
|
@_authform_base_url = _authform_base_url
|
19
|
+
|
20
|
+
parse!
|
21
|
+
end
|
22
|
+
|
23
|
+
def parse!
|
24
|
+
!!_id
|
25
|
+
rescue
|
26
|
+
raise Gatleon::Authform::Rails::Error
|
12
27
|
end
|
13
28
|
|
14
29
|
# Getters
|
15
30
|
#
|
16
31
|
def _id
|
17
|
-
|
32
|
+
data["_id"]
|
18
33
|
end
|
19
34
|
|
20
35
|
def _email
|
21
|
-
|
36
|
+
data["_email"]
|
22
37
|
end
|
23
38
|
|
24
39
|
# Getters
|
25
40
|
#
|
26
41
|
def [](key)
|
27
|
-
|
42
|
+
data[key.to_s]
|
28
43
|
end
|
29
44
|
|
30
45
|
# Setters
|
@@ -38,8 +53,31 @@ module Gatleon
|
|
38
53
|
|
39
54
|
raise Gatleon::Authform::Rails::Error, "only characters a-z, A-Z, 0-9, and _ permitted in field name" unless key.match?(PERMITTED_CHARS)
|
40
55
|
|
41
|
-
|
56
|
+
data[key] = value.to_s
|
57
|
+
end
|
58
|
+
|
59
|
+
def data
|
60
|
+
_json["data"]
|
61
|
+
end
|
62
|
+
|
63
|
+
def _json
|
64
|
+
@_json ||= JSON.parse(@_cookies[@_authform_user_cookie_key])
|
65
|
+
end
|
66
|
+
|
67
|
+
def signoff!
|
68
|
+
if @_domain
|
69
|
+
@_cookies.delete(@_authform_user_cookie_key, domain: @_domain)
|
70
|
+
else
|
71
|
+
@_cookies.delete(@_authform_user_cookie_key)
|
72
|
+
end
|
42
73
|
end
|
74
|
+
alias_method :sign_off!, :signoff!
|
75
|
+
alias_method :signout!, :signoff!
|
76
|
+
alias_method :sign_out!, :signoff!
|
77
|
+
alias_method :logout!, :signoff!
|
78
|
+
alias_method :log_out!, :signoff!
|
79
|
+
alias_method :logoff!, :signoff!
|
80
|
+
alias_method :log_off!, :signoff!
|
43
81
|
|
44
82
|
private
|
45
83
|
|
metadata
CHANGED
@@ -1,15 +1,29 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: gatleon-authform-rails
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.5.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- gatleon
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-
|
12
|
-
dependencies:
|
11
|
+
date: 2020-08-17 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: xxhash
|
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'
|
13
27
|
description: add authentication to your application - in 1 minute or less
|
14
28
|
email:
|
15
29
|
- ''
|
@@ -19,6 +33,7 @@ extra_rdoc_files: []
|
|
19
33
|
files:
|
20
34
|
- ".gitignore"
|
21
35
|
- ".rspec"
|
36
|
+
- ".ruby-version"
|
22
37
|
- ".travis.yml"
|
23
38
|
- Gemfile
|
24
39
|
- Gemfile.lock
|
@@ -28,7 +43,6 @@ files:
|
|
28
43
|
- bin/console
|
29
44
|
- bin/setup
|
30
45
|
- gatleon-authform-rails.gemspec
|
31
|
-
- gatleon-authform-rails.png
|
32
46
|
- lib/gatleon/authform/rails.rb
|
33
47
|
- lib/gatleon/authform/rails/concern.rb
|
34
48
|
- lib/gatleon/authform/rails/user.rb
|
data/gatleon-authform-rails.png
DELETED
Binary file
|