gatleon-authform-rails 0.3.0 → 0.7.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +5 -3
- data/README.md +31 -14
- data/gatleon-authform-rails.gemspec +2 -0
- data/lib/gatleon/authform/rails.rb +0 -1
- data/lib/gatleon/authform/rails/concern.rb +12 -4
- data/lib/gatleon/authform/rails/user.rb +5 -5
- 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: 653570cc8138e798a9404b727ac68ec1f7351953cd59a7e7ece1f08284bffcff
|
4
|
+
data.tar.gz: a6ebd4fc079dd0d383e21201cd58e71adc23eed8de1759786b9813b57390688e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c01f61589cfc34bdccd07d1ae70789d78a378d9fd3d8665a67cedfd997a2532121f9d020f294575097bf49e73d88e85aeb58d5ddba1bf988488cd6ab7fc15aac
|
7
|
+
data.tar.gz: b7d9365cd368eaa4ccda1985dfe1e33f4ff36b124304a17dfdb364ca8b0de77edee9d6b75265bb06bba45b6cc506d87fa7a55e37bbc25c1f0a04c1c7d31018da
|
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.7.0)
|
5
|
+
xxhash
|
5
6
|
|
6
7
|
GEM
|
7
8
|
remote: https://rubygems.org/
|
@@ -86,7 +87,7 @@ GEM
|
|
86
87
|
nio4r (2.5.2)
|
87
88
|
nokogiri (1.10.9)
|
88
89
|
mini_portile2 (~> 2.4.0)
|
89
|
-
rack (2.2.
|
90
|
+
rack (2.2.3)
|
90
91
|
rack-test (1.1.0)
|
91
92
|
rack (>= 1.0, < 3)
|
92
93
|
rails (6.0.2.2)
|
@@ -142,7 +143,8 @@ GEM
|
|
142
143
|
thread_safe (~> 0.1)
|
143
144
|
websocket-driver (0.7.1)
|
144
145
|
websocket-extensions (>= 0.1.0)
|
145
|
-
websocket-extensions (0.1.
|
146
|
+
websocket-extensions (0.1.5)
|
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="
|
55
|
+
<form action="<%= signon_url %>" 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,4 +1,4 @@
|
|
1
|
-
require "
|
1
|
+
require "xxhash"
|
2
2
|
|
3
3
|
module Gatleon
|
4
4
|
module Authform
|
@@ -8,22 +8,30 @@ module Gatleon
|
|
8
8
|
secret_key:,
|
9
9
|
domain: nil,
|
10
10
|
current_user_method_name: "current_user",
|
11
|
-
|
11
|
+
signon_url_method_name: "signon_url",
|
12
|
+
_authform_base_url: "https://authformapi.gatleon.com")
|
12
13
|
super() do
|
13
14
|
extend ActiveSupport::Concern
|
14
15
|
|
15
16
|
included do
|
16
17
|
helper_method "#{current_user_method_name}".to_sym
|
18
|
+
helper_method "#{signon_url_method_name}".to_sym
|
19
|
+
|
17
20
|
before_action :_exchange_user_voucher_for_user
|
18
21
|
end
|
19
22
|
|
20
23
|
private
|
21
24
|
|
25
|
+
# defaults to signon_url
|
26
|
+
define_method signon_url_method_name do
|
27
|
+
"#{_authform_base_url}/v1/form/#{public_key}"
|
28
|
+
end
|
29
|
+
|
22
30
|
# defaults to current_user
|
23
31
|
define_method current_user_method_name do
|
24
32
|
begin
|
25
33
|
Gatleon::Authform::Rails::User.new(_cookies: cookies,
|
26
|
-
|
34
|
+
_authform_user_cookie_key: _authform_user_cookie_key,
|
27
35
|
_form_secret_key: secret_key,
|
28
36
|
_domain: domain,
|
29
37
|
_authform_base_url: _authform_base_url)
|
@@ -51,7 +59,7 @@ module Gatleon
|
|
51
59
|
end
|
52
60
|
|
53
61
|
define_method :_authform_user_cookie_key do
|
54
|
-
|
62
|
+
"#{public_key}_#{XXhash.xxh32(domain)}"
|
55
63
|
end
|
56
64
|
|
57
65
|
define_method :_cookie_attrs do |value|
|
@@ -7,12 +7,12 @@ module Gatleon
|
|
7
7
|
PERMITTED_CHARS = /\A[a-zA-Z0-9_)]*\z/
|
8
8
|
|
9
9
|
def initialize(_cookies:,
|
10
|
-
|
10
|
+
_authform_user_cookie_key:,
|
11
11
|
_form_secret_key:,
|
12
12
|
_domain:,
|
13
13
|
_authform_base_url:)
|
14
14
|
@_cookies = _cookies
|
15
|
-
@
|
15
|
+
@_authform_user_cookie_key = _authform_user_cookie_key
|
16
16
|
@_form_secret_key = _form_secret_key
|
17
17
|
@_domain = _domain
|
18
18
|
@_authform_base_url = _authform_base_url
|
@@ -61,14 +61,14 @@ module Gatleon
|
|
61
61
|
end
|
62
62
|
|
63
63
|
def _json
|
64
|
-
@_json ||= JSON.parse(@_cookies[@
|
64
|
+
@_json ||= JSON.parse(@_cookies[@_authform_user_cookie_key])
|
65
65
|
end
|
66
66
|
|
67
67
|
def signoff!
|
68
68
|
if @_domain
|
69
|
-
@_cookies.delete(@
|
69
|
+
@_cookies.delete(@_authform_user_cookie_key, domain: @_domain)
|
70
70
|
else
|
71
|
-
@_cookies.delete(@
|
71
|
+
@_cookies.delete(@_authform_user_cookie_key)
|
72
72
|
end
|
73
73
|
end
|
74
74
|
alias_method :sign_off!, :signoff!
|
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.7.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-20 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
|