gatleon-authform-rails 0.2.0 → 0.6.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/Gemfile.lock +3 -1
- data/README.md +31 -14
- data/gatleon-authform-rails.gemspec +2 -0
- data/lib/gatleon/authform/rails/concern.rb +9 -5
- data/lib/gatleon/authform/rails/user.rb +45 -7
- data/lib/gatleon/authform/rails/version.rb +1 -1
- metadata +17 -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: f583501fb5e708d2e8e58b3410d38dfd1ff87f7224753657c95edc4737ccc4b4
|
4
|
+
data.tar.gz: 0f509e2572a8b9c2356f1b6c59e2c9f0dce1b2cb07fceb315b96937ee87c93cb
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a26d09bed9e2f0f312e76984ce9779ea367e9c9a534db4dbedcebb02aba61ce31a206d494566fbb2dfd51af00a2e7e6c299ea030175911a0a63ca815b881faae
|
7
|
+
data.tar.gz: 4c03dfb1ed74fa7266c1dfc235aa728f0a53f3a3ec2b2547de4e8225566fe2bef9ede16386c14558634f729fb4a8841454775c030461a190527aa6631fcbd6b2
|
data/.gitignore
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.6.0)
|
5
|
+
xxhash
|
5
6
|
|
6
7
|
GEM
|
7
8
|
remote: https://rubygems.org/
|
@@ -143,6 +144,7 @@ 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)
|
146
148
|
yard (0.9.24)
|
147
149
|
zeitwerk (2.3.0)
|
148
150
|
|
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,22 +16,33 @@ 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
|
|
32
41
|
def index
|
33
42
|
erb = <<~ERB
|
34
43
|
<h1>Profile</h1>
|
35
|
-
<p style="color: green;">You are signed in
|
36
|
-
<p><%= current_user %></p>
|
44
|
+
<p style="color: green;">You are signed in. (<a href="/profile/signoff">sign off</a>)</p>
|
45
|
+
<p><%= current_user._id %> <%= current_user._email %></p>
|
37
46
|
ERB
|
38
47
|
|
39
48
|
render inline: erb
|
@@ -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://
|
55
|
+
<form action="https://authformapi.gatleon.com/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>
|
@@ -52,6 +62,12 @@ class ProfileController < ActionController::Base
|
|
52
62
|
render inline: erb
|
53
63
|
end
|
54
64
|
|
65
|
+
def signoff
|
66
|
+
current_user.signoff!
|
67
|
+
|
68
|
+
redirect_to(profile_signin_path) and return
|
69
|
+
end
|
70
|
+
|
55
71
|
private
|
56
72
|
|
57
73
|
def require_login
|
@@ -64,12 +80,13 @@ class ProfileController < ActionController::Base
|
|
64
80
|
end
|
65
81
|
```
|
66
82
|
|
67
|
-
add profile routes to routes.rb
|
83
|
+
add profile routes to routes.rb:
|
68
84
|
|
69
85
|
```ruby
|
70
86
|
Rails.application.routes.draw do
|
71
|
-
get
|
72
|
-
get
|
87
|
+
get "/profile", to: "profile#index", as: :profile
|
88
|
+
get "/profile/signin", to: "profile#signin", as: :profile_signin
|
89
|
+
get "/profile/signoff", to: "profile#signoff", as: :profile_signoff
|
73
90
|
end
|
74
91
|
```
|
75
92
|
|
@@ -1,3 +1,5 @@
|
|
1
|
+
require "xxhash"
|
2
|
+
|
1
3
|
module Gatleon
|
2
4
|
module Authform
|
3
5
|
module Rails
|
@@ -6,7 +8,7 @@ module Gatleon
|
|
6
8
|
secret_key:,
|
7
9
|
domain: nil,
|
8
10
|
current_user_method_name: "current_user",
|
9
|
-
_authform_base_url: "https://
|
11
|
+
_authform_base_url: "https://authformapi.gatleon.com")
|
10
12
|
super() do
|
11
13
|
extend ActiveSupport::Concern
|
12
14
|
|
@@ -20,9 +22,11 @@ module Gatleon
|
|
20
22
|
# defaults to current_user
|
21
23
|
define_method current_user_method_name do
|
22
24
|
begin
|
23
|
-
|
24
|
-
|
25
|
-
|
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)
|
26
30
|
rescue
|
27
31
|
nil
|
28
32
|
end
|
@@ -47,7 +51,7 @@ module Gatleon
|
|
47
51
|
end
|
48
52
|
|
49
53
|
define_method :_authform_user_cookie_key do
|
50
|
-
|
54
|
+
"#{public_key}_#{XXhash.xxh32(domain)}"
|
51
55
|
end
|
52
56
|
|
53
57
|
define_method :_cookie_attrs do |value|
|
@@ -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.6.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-18 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
|
- ''
|
@@ -29,7 +43,6 @@ files:
|
|
29
43
|
- bin/console
|
30
44
|
- bin/setup
|
31
45
|
- gatleon-authform-rails.gemspec
|
32
|
-
- gatleon-authform-rails.png
|
33
46
|
- lib/gatleon/authform/rails.rb
|
34
47
|
- lib/gatleon/authform/rails/concern.rb
|
35
48
|
- lib/gatleon/authform/rails/user.rb
|
data/gatleon-authform-rails.png
DELETED
Binary file
|