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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: b75dc2e45b5f446a8bf28e95e4d48eb096d5acef5de2b2cb453c3cc5ceaa626a
4
- data.tar.gz: 8568b98d4cfb5e26b3c3d6d9d0bc5a0591d47a4a4e31dbfeb89bc0d9fd15757d
3
+ metadata.gz: 653570cc8138e798a9404b727ac68ec1f7351953cd59a7e7ece1f08284bffcff
4
+ data.tar.gz: a6ebd4fc079dd0d383e21201cd58e71adc23eed8de1759786b9813b57390688e
5
5
  SHA512:
6
- metadata.gz: 990f100b99d36e4c6b005a18dc270176fe25a86ce753731b3958bdaba10b74bf2fdd34813facd7768a25be4671f27d22cf4ca5993a6760d26714d4af30816e80
7
- data.tar.gz: 507266798a6df6e2cea497455779d7a1e888dcaf0a697db6d5fe7f73a593866659de8eca4eb0ce789760cb710afb6d5fe067d3a20314f7c1ac06c58a8a5c5d80
6
+ metadata.gz: c01f61589cfc34bdccd07d1ae70789d78a378d9fd3d8665a67cedfd997a2532121f9d020f294575097bf49e73d88e85aeb58d5ddba1bf988488cd6ab7fc15aac
7
+ data.tar.gz: b7d9365cd368eaa4ccda1985dfe1e33f4ff36b124304a17dfdb364ca8b0de77edee9d6b75265bb06bba45b6cc506d87fa7a55e37bbc25c1f0a04c1c7d31018da
@@ -1,7 +1,8 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- gatleon-authform-rails (0.3.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.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.4)
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
- ![authform-rails](https://raw.githubusercontent.com/gatleon/gatleon-authform-rails/master/gatleon-authform-rails.png)
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
- add a profile controller
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
- AUTHFORM_FORM_SECRET_KEY = "" # Available at https://authform.gatleon.com. coming soon!
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.</p>
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://authform.gatleon.com/v1/form/<%= ProfileController::AUTHFORM_FORM_PUBLIC_KEY %>" method="POST">
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 '/profile', to: 'profile#index', as: 'profile'
72
- get '/profile/signin', to: 'profile#signin', as: 'profile_signin'
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
 
@@ -24,4 +24,6 @@ Gem::Specification.new do |spec|
24
24
  spec.bindir = "exe"
25
25
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
26
26
  spec.require_paths = ["lib"]
27
+
28
+ spec.add_runtime_dependency "xxhash"
27
29
  end
@@ -7,7 +7,6 @@ module Gatleon
7
7
  module Authform
8
8
  module Rails
9
9
  class Error < StandardError; end
10
- # Your code goes here...
11
10
  end
12
11
  end
13
12
  end
@@ -1,4 +1,4 @@
1
- require "json"
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
- _authform_base_url: "https://authform.gatleon.com")
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
- _form_public_key: public_key,
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
- public_key # allows for multiple forms per site
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
- _form_public_key:,
10
+ _authform_user_cookie_key:,
11
11
  _form_secret_key:,
12
12
  _domain:,
13
13
  _authform_base_url:)
14
14
  @_cookies = _cookies
15
- @_form_public_key = _form_public_key
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[@_form_public_key])
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(@_form_public_key, domain: @_domain)
69
+ @_cookies.delete(@_authform_user_cookie_key, domain: @_domain)
70
70
  else
71
- @_cookies.delete(@_form_public_key)
71
+ @_cookies.delete(@_authform_user_cookie_key)
72
72
  end
73
73
  end
74
74
  alias_method :sign_off!, :signoff!
@@ -1,7 +1,7 @@
1
1
  module Gatleon
2
2
  module Authform
3
3
  module Rails
4
- VERSION = "0.3.0"
4
+ VERSION = "0.7.0"
5
5
  end
6
6
  end
7
7
  end
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.3.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-05-02 00:00:00.000000000 Z
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
Binary file