gatleon-rails 0.1.10 → 0.2.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: 3fbd403fe8bde2764f7cb539ec19c1fe45df93dc419a99e750d953761b0a1f65
4
- data.tar.gz: 312643f43d5cc728b66a57749bcabce17d6a2e5831a16b532252b39cf4030e87
3
+ metadata.gz: aa250f4e4682c142505fe3a2438c49872edb1c4030297607e342ba98b6dc0006
4
+ data.tar.gz: 65461cf8b9d1170a0413ac602b90d8a7f5e31590c13524ac4d2c8e2a7195f4a0
5
5
  SHA512:
6
- metadata.gz: b7b9ad87afa7b1a9d50ceef24d7cead481639868d5293a9fb3e7ff12529b2bee0477c69dad5b927bda4f535bc71cb7a7010e75cd923d1ecf09b99c2695634ced
7
- data.tar.gz: ee3817b847928391a5123b2bd04bce9696d48b913b9a67e2611b5daa0dc0530cbb6ab72d2eeb1df1b0e3dc3ccae8220d8691cac5b68c37a53cdffe7da368982e
6
+ metadata.gz: 1399334d4857f90c62d56a29f00c7abb5c04b2aafb996d6e6409e1b12a50dfdb124748943467c7dc2afb44c1775546cff6f79d113cf2d39e83cde5dc75f6be09
7
+ data.tar.gz: 748b6a39bf95df531e76f5b5b64e10912768524efc2216af439d3c423ba93f95d71c71a7ec8e1dec3ff5b121f8554088dea5170c907009dfbf9ba73375807273
data/.gitignore CHANGED
@@ -9,3 +9,4 @@
9
9
 
10
10
  # rspec failure tracking
11
11
  .rspec_status
12
+ *.swp
data/Gemfile CHANGED
@@ -5,3 +5,4 @@ gemspec
5
5
 
6
6
  gem "rake", "~> 12.0"
7
7
  gem "rspec", "~> 3.0"
8
+ gem "rails"
@@ -1,12 +1,119 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- gatleon-rails (0.1.10)
4
+ gatleon-rails (0.2.0)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
8
8
  specs:
9
+ actioncable (6.0.2.2)
10
+ actionpack (= 6.0.2.2)
11
+ nio4r (~> 2.0)
12
+ websocket-driver (>= 0.6.1)
13
+ actionmailbox (6.0.2.2)
14
+ actionpack (= 6.0.2.2)
15
+ activejob (= 6.0.2.2)
16
+ activerecord (= 6.0.2.2)
17
+ activestorage (= 6.0.2.2)
18
+ activesupport (= 6.0.2.2)
19
+ mail (>= 2.7.1)
20
+ actionmailer (6.0.2.2)
21
+ actionpack (= 6.0.2.2)
22
+ actionview (= 6.0.2.2)
23
+ activejob (= 6.0.2.2)
24
+ mail (~> 2.5, >= 2.5.4)
25
+ rails-dom-testing (~> 2.0)
26
+ actionpack (6.0.2.2)
27
+ actionview (= 6.0.2.2)
28
+ activesupport (= 6.0.2.2)
29
+ rack (~> 2.0, >= 2.0.8)
30
+ rack-test (>= 0.6.3)
31
+ rails-dom-testing (~> 2.0)
32
+ rails-html-sanitizer (~> 1.0, >= 1.2.0)
33
+ actiontext (6.0.2.2)
34
+ actionpack (= 6.0.2.2)
35
+ activerecord (= 6.0.2.2)
36
+ activestorage (= 6.0.2.2)
37
+ activesupport (= 6.0.2.2)
38
+ nokogiri (>= 1.8.5)
39
+ actionview (6.0.2.2)
40
+ activesupport (= 6.0.2.2)
41
+ builder (~> 3.1)
42
+ erubi (~> 1.4)
43
+ rails-dom-testing (~> 2.0)
44
+ rails-html-sanitizer (~> 1.1, >= 1.2.0)
45
+ activejob (6.0.2.2)
46
+ activesupport (= 6.0.2.2)
47
+ globalid (>= 0.3.6)
48
+ activemodel (6.0.2.2)
49
+ activesupport (= 6.0.2.2)
50
+ activerecord (6.0.2.2)
51
+ activemodel (= 6.0.2.2)
52
+ activesupport (= 6.0.2.2)
53
+ activestorage (6.0.2.2)
54
+ actionpack (= 6.0.2.2)
55
+ activejob (= 6.0.2.2)
56
+ activerecord (= 6.0.2.2)
57
+ marcel (~> 0.3.1)
58
+ activesupport (6.0.2.2)
59
+ concurrent-ruby (~> 1.0, >= 1.0.2)
60
+ i18n (>= 0.7, < 2)
61
+ minitest (~> 5.1)
62
+ tzinfo (~> 1.1)
63
+ zeitwerk (~> 2.2)
64
+ builder (3.2.4)
65
+ concurrent-ruby (1.1.6)
66
+ crass (1.0.6)
9
67
  diff-lcs (1.3)
68
+ erubi (1.9.0)
69
+ globalid (0.4.2)
70
+ activesupport (>= 4.2.0)
71
+ i18n (1.8.2)
72
+ concurrent-ruby (~> 1.0)
73
+ loofah (2.5.0)
74
+ crass (~> 1.0.2)
75
+ nokogiri (>= 1.5.9)
76
+ mail (2.7.1)
77
+ mini_mime (>= 0.1.1)
78
+ marcel (0.3.3)
79
+ mimemagic (~> 0.3.2)
80
+ method_source (1.0.0)
81
+ mimemagic (0.3.4)
82
+ mini_mime (1.0.2)
83
+ mini_portile2 (2.4.0)
84
+ minitest (5.14.0)
85
+ nio4r (2.5.2)
86
+ nokogiri (1.10.9)
87
+ mini_portile2 (~> 2.4.0)
88
+ rack (2.2.2)
89
+ rack-test (1.1.0)
90
+ rack (>= 1.0, < 3)
91
+ rails (6.0.2.2)
92
+ actioncable (= 6.0.2.2)
93
+ actionmailbox (= 6.0.2.2)
94
+ actionmailer (= 6.0.2.2)
95
+ actionpack (= 6.0.2.2)
96
+ actiontext (= 6.0.2.2)
97
+ actionview (= 6.0.2.2)
98
+ activejob (= 6.0.2.2)
99
+ activemodel (= 6.0.2.2)
100
+ activerecord (= 6.0.2.2)
101
+ activestorage (= 6.0.2.2)
102
+ activesupport (= 6.0.2.2)
103
+ bundler (>= 1.3.0)
104
+ railties (= 6.0.2.2)
105
+ sprockets-rails (>= 2.0.0)
106
+ rails-dom-testing (2.0.3)
107
+ activesupport (>= 4.2.0)
108
+ nokogiri (>= 1.6)
109
+ rails-html-sanitizer (1.3.0)
110
+ loofah (~> 2.3)
111
+ railties (6.0.2.2)
112
+ actionpack (= 6.0.2.2)
113
+ activesupport (= 6.0.2.2)
114
+ method_source
115
+ rake (>= 0.8.7)
116
+ thor (>= 0.20.3, < 2.0)
10
117
  rake (12.3.3)
11
118
  rspec (3.9.0)
12
119
  rspec-core (~> 3.9.0)
@@ -21,12 +128,28 @@ GEM
21
128
  diff-lcs (>= 1.2.0, < 2.0)
22
129
  rspec-support (~> 3.9.0)
23
130
  rspec-support (3.9.2)
131
+ sprockets (4.0.0)
132
+ concurrent-ruby (~> 1.0)
133
+ rack (> 1, < 3)
134
+ sprockets-rails (3.2.1)
135
+ actionpack (>= 4.0)
136
+ activesupport (>= 4.0)
137
+ sprockets (>= 3.0.0)
138
+ thor (1.0.1)
139
+ thread_safe (0.3.6)
140
+ tzinfo (1.2.7)
141
+ thread_safe (~> 0.1)
142
+ websocket-driver (0.7.1)
143
+ websocket-extensions (>= 0.1.0)
144
+ websocket-extensions (0.1.4)
145
+ zeitwerk (2.3.0)
24
146
 
25
147
  PLATFORMS
26
148
  ruby
27
149
 
28
150
  DEPENDENCIES
29
151
  gatleon-rails!
152
+ rails
30
153
  rake (~> 12.0)
31
154
  rspec (~> 3.0)
32
155
 
data/README.md CHANGED
@@ -1,39 +1,77 @@
1
- # Gatleon::Rails
1
+ # Gatleon Rails
2
2
 
3
- Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/gatleon/rails`. To experiment with that code, run `bin/console` for an interactive prompt.
4
-
5
- TODO: Delete this and the text above, and describe your gem
3
+ add authentication to your website - in 1 minute or less.
6
4
 
7
5
  ## Installation
8
6
 
9
7
  Add this line to your application's Gemfile:
10
8
 
11
9
  ```ruby
12
- gem 'gatleon-rails'
10
+ gem "gatleon-rails"
13
11
  ```
14
12
 
15
13
  And then execute:
16
14
 
17
- $ bundle install
18
-
19
- Or install it yourself as:
20
-
21
- $ gem install gatleon-rails
22
-
23
- ## Usage
24
-
25
- TODO: Write usage instructions here
26
-
27
- ## Development
15
+ ```
16
+ $ bundle install
17
+ ```
28
18
 
29
- After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
19
+ Add a profile controller
30
20
 
31
- To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
21
+ ```ruby
22
+ class ProfileController < ActionController::Base
23
+ AUTHFORM_FORM_PUBLIC_KEY = "" # Available at https://authform.gatleon.com. coming soon!
24
+ AUTHFORM_FORM_SECRET_KEY = "" # Available at https://authform.gatleon.com. coming soon!
25
+
26
+ include Gatleon::Rails::Authform::Concern.new(public_key: AUTHFORM_FORM_PUBLIC_KEY, secret_key: AUTHFORM_FORM_SECRET_KEY)
27
+
28
+ before_action :require_login, only: [:index]
29
+
30
+ def index
31
+ erb = <<~ERB
32
+ <h1>Profile</h1>
33
+ <p style="color: green;">You are signed in.</p>
34
+ <p><%= current_user %></p>
35
+ ERB
36
+
37
+ render inline: erb
38
+ end
39
+
40
+ def signin
41
+ erb = <<~ERB
42
+ <p style="color: red;"><%= flash[:error] %></p>
43
+ <h1>Sign In</h1>
44
+ <form action="https://authform.gatleon.com/v1/form/<%= ProfileController::AUTHFORM_FORM_PUBLIC_KEY %>" method="POST">
45
+ <input type="email" name="email">
46
+ <button type="submit">Sign In</button>
47
+ </form>
48
+ ERB
49
+
50
+ render inline: erb
51
+ end
52
+
53
+ private
54
+
55
+ def require_login
56
+ unless current_user
57
+ flash[:error] = "Sign in, please."
58
+
59
+ redirect_to(profile_signin_path) and return
60
+ end
61
+ end
62
+ end
63
+ ```
32
64
 
33
- ## Contributing
65
+ Add profile routes to routes.rb
34
66
 
35
- Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/gatleon-rails.
67
+ ```ruby
68
+ Rails.application.routes.draw do
69
+ get '/profile', to: 'profile#index', as: 'profile'
70
+ get '/profile/signin', to: 'profile#signin', as: 'profile_signin'
71
+ end
72
+ ```
36
73
 
74
+ That's it!
37
75
 
38
76
  ## License
39
77
 
@@ -1,5 +1,6 @@
1
1
  require "net/http"
2
2
  require "gatleon/rails/version"
3
+ require "gatleon/rails/authform/user"
3
4
  require "gatleon/rails/authform/concern"
4
5
 
5
6
  module Gatleon
@@ -2,7 +2,8 @@ module Gatleon
2
2
  module Rails
3
3
  module Authform
4
4
  class Concern < Module
5
- def initialize(form_uid:,
5
+ def initialize(public_key:,
6
+ secret_key:,
6
7
  current_user_method_name: "current_user",
7
8
  _authform_base_url: "https://authform.gatleon.com")
8
9
  super() do
@@ -25,7 +26,7 @@ module Gatleon
25
26
  end
26
27
 
27
28
  define_method :_exchange_user_voucher_for_user do
28
- if params[:_authformForm] == form_uid && params[:_authformUserVoucher]
29
+ if params[:_authformForm] == public_key && params[:_authformUserVoucher]
29
30
  # TODO: headers for api verification
30
31
 
31
32
  uri = URI("#{_authform_base_url}/v1/exchangeUserVoucherForUser/#{params[:_authformUserVoucher]}")
@@ -48,7 +49,7 @@ module Gatleon
48
49
  end
49
50
 
50
51
  define_method :_authform_user_cookie_key do
51
- form_uid # allows for multiple forms per site
52
+ public_key # allows for multiple forms per site
52
53
  end
53
54
  end
54
55
  end
@@ -0,0 +1,62 @@
1
+ module Gatleon
2
+ module Rails
3
+ module Authform
4
+ class User
5
+ PERMITTED_CHARS = /\A[a-zA-Z0-9_)]*\z/
6
+
7
+ def initialize(json:, _form_secret_key:, _authform_base_url:)
8
+ @json = json
9
+
10
+ @_form_secret_key = _form_secret_key
11
+ @_authform_base_url = _authform_base_url
12
+ end
13
+
14
+ # Getters
15
+ #
16
+ def _id
17
+ @json["_id"]
18
+ end
19
+
20
+ def _email
21
+ @json["_email"]
22
+ end
23
+
24
+ # Getters
25
+ #
26
+ def [](key)
27
+ @json[key.to_s]
28
+ end
29
+
30
+ # Setters
31
+ #
32
+ def []=(key, value)
33
+ key = _clean_key(key)
34
+
35
+ raise ArgumentError, "can't set reserved field name #{key}" if key[0] == "_" # anything starting with _
36
+
37
+ raise ArgumentError, "can't set empty field name" if key == ""
38
+
39
+ raise ArgumentError, "only characters a-z, A-Z, 0-9, and _ permitted in field name" unless key.match?(PERMITTED_CHARS)
40
+
41
+ @json[key] = value.to_s
42
+ end
43
+
44
+ private
45
+
46
+ def _persist(key, value)
47
+ uri = _persist_url(key, vlue)
48
+
49
+ Net::HTTP.get_response(uri) # TODO: move to post request
50
+ end
51
+
52
+ def _persist_url(key, value)
53
+ URI("#{@_authform_base_url}/v1/setUser?_id=#{_id}&_secretKey=#{@_form_secret_key}&#{key}=#{value}")
54
+ end
55
+
56
+ def _clean_key(k_or_v)
57
+ k_or_v.to_s.strip
58
+ end
59
+ end
60
+ end
61
+ end
62
+ end
@@ -1,5 +1,5 @@
1
1
  module Gatleon
2
2
  module Rails
3
- VERSION = "0.1.10"
3
+ VERSION = "0.2.0"
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gatleon-rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.10
4
+ version: 0.2.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-04-04 00:00:00.000000000 Z
11
+ date: 2020-04-21 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: add authentication to your website - in 1 minute or less.
14
14
  email:
@@ -30,6 +30,7 @@ files:
30
30
  - gatleon-rails.gemspec
31
31
  - lib/gatleon/rails.rb
32
32
  - lib/gatleon/rails/authform/concern.rb
33
+ - lib/gatleon/rails/authform/user.rb
33
34
  - lib/gatleon/rails/version.rb
34
35
  homepage: https://gatleon.com
35
36
  licenses: