app_rail-airtable 0.4.5 → 0.4.8

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: 28964042f95bd7532166f56c9f95550573038d02bf9097eeff287698a2dd261d
4
- data.tar.gz: 64ddc07fb9c729ae38940e0111346465bee157ee600a69265b47f9ab4163c51e
3
+ metadata.gz: 3d413292d55b91966eeed50458ef1cd264cc278add196d53fbab2633dfd406d3
4
+ data.tar.gz: e16281efca091bc9d9e2dc2abf2f81c4c16416cd9cf27a6b34127bd191899bb0
5
5
  SHA512:
6
- metadata.gz: 05efe59ea2696590acf285e0c641f5c1ef42961f42b46aaed2c316d449ef797e06d3f9f15a14488ee4385e29028609bac35e67dcca41fdb6fa44edc35f51a346
7
- data.tar.gz: e28840bfed651fee92759cf4102157b7a45472c0bb87b7a0d1e8bafe81afce034b2e8db3e6090045063b01d3c990e8e369ce8d682c5f7fc988e776801968cd0f
6
+ metadata.gz: a4c6b3fe35603c645186b1d45d67d16f4afa1d556500abb1f5467b9ae78be4b29dc847e85a9c3379ecf75ebf0b94894e5d620557096eec9abad06d8e1248017b
7
+ data.tar.gz: e61beebcf401102669f1707ddc4f2a5b6b9f7d25585b05cbace9198a1d55196739ca22e73297699fc5413c1226d1a050c754cd7f2fdbd49bdc34a436950dd90f
data/CHANGELOG.md CHANGED
@@ -1,3 +1,7 @@
1
+ # 0.4.6
2
+ * Add authenticatable_resource POST / DELETE `/<resource>/session` routes for sign in and sign out
3
+ * Simplify sign in methods & remove Authenticatable#create_session_as_json
4
+
1
5
  # 0.4.0
2
6
 
3
7
  ### Breaking changes
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- app_rail-airtable (0.4.5)
4
+ app_rail-airtable (0.4.8)
5
5
  activesupport
6
6
  airrecord
7
7
  app_rail-steps
@@ -14,7 +14,7 @@ PATH
14
14
  GEM
15
15
  remote: https://rubygems.org/
16
16
  specs:
17
- activesupport (7.0.2.4)
17
+ activesupport (7.0.4)
18
18
  concurrent-ruby (~> 1.0, >= 1.0.2)
19
19
  i18n (>= 1.6, < 2)
20
20
  minitest (>= 5.1)
@@ -23,28 +23,28 @@ GEM
23
23
  faraday (>= 1.0, < 3.0)
24
24
  faraday-net_http_persistent
25
25
  net-http-persistent
26
- app_rail-steps (0.2.9)
27
- bcrypt (3.1.17)
26
+ app_rail-steps (0.2.16)
27
+ bcrypt (3.1.18)
28
28
  byebug (11.1.3)
29
29
  concurrent-ruby (1.1.10)
30
- connection_pool (2.2.5)
30
+ connection_pool (2.3.0)
31
31
  diff-lcs (1.4.4)
32
- faraday (2.2.0)
33
- faraday-net_http (~> 2.0)
32
+ faraday (2.6.0)
33
+ faraday-net_http (>= 2.0, < 3.1)
34
34
  ruby2_keywords (>= 0.0.4)
35
- faraday-net_http (2.0.2)
36
- faraday-net_http_persistent (2.0.1)
37
- faraday-net_http
35
+ faraday-net_http (3.0.1)
36
+ faraday-net_http_persistent (2.1.0)
37
+ faraday (~> 2.5)
38
38
  net-http-persistent (~> 4.0)
39
- i18n (1.10.0)
39
+ i18n (1.12.0)
40
40
  concurrent-ruby (~> 1.0)
41
- minitest (5.15.0)
42
- mustermann (1.1.1)
41
+ minitest (5.16.3)
42
+ mustermann (2.0.2)
43
43
  ruby2_keywords (~> 0.0.1)
44
44
  net-http-persistent (4.0.1)
45
45
  connection_pool (~> 2.2)
46
46
  rack (2.2.3)
47
- rack-protection (2.2.0)
47
+ rack-protection (2.2.2)
48
48
  rack
49
49
  rack-test (1.1.0)
50
50
  rack (>= 1.0, < 3)
@@ -63,14 +63,14 @@ GEM
63
63
  rspec-support (~> 3.10.0)
64
64
  rspec-support (3.10.2)
65
65
  ruby2_keywords (0.0.5)
66
- sinatra (2.2.0)
67
- mustermann (~> 1.0)
66
+ sinatra (2.2.2)
67
+ mustermann (~> 2.0)
68
68
  rack (~> 2.2)
69
- rack-protection (= 2.2.0)
69
+ rack-protection (= 2.2.2)
70
70
  tilt (~> 2.0)
71
71
  thor (1.1.0)
72
- tilt (2.0.10)
73
- tzinfo (2.0.4)
72
+ tilt (2.0.11)
73
+ tzinfo (2.0.5)
74
74
  concurrent-ruby (~> 1.0)
75
75
 
76
76
  PLATFORMS
@@ -12,7 +12,7 @@ module AppRail
12
12
 
13
13
  def self.included(klass)
14
14
  klass.extend(ClassMethods)
15
- klass.prepend(InstanceMethods) # prepends `initialize` instance method in order to take precedence over Airrecord::Table#initialize
15
+ klass.prepend(InstanceMethods)
16
16
  end
17
17
 
18
18
  module ClassMethods
@@ -24,15 +24,6 @@ module AppRail
24
24
  user
25
25
  end
26
26
 
27
- def create_session_as_json(email:, password:)
28
- user = find_by_email_and_password(email, password)
29
- return nil unless user
30
-
31
- user['Access Token'] = next_access_token
32
- user.save
33
- user&.oauth_session
34
- end
35
-
36
27
  def find_by_email_and_password(email, password)
37
28
  user = find_by_email(email)
38
29
  user&.valid_password?(password) ? user : nil
@@ -56,25 +47,31 @@ module AppRail
56
47
  end
57
48
 
58
49
  module InstanceMethods
59
- def initialize(*args)
60
- if (kwargs = args.first) && kwargs.is_a?(Hash) && kwargs.size == 2 && kwargs.key?(:email) && kwargs.key?(:password)
61
- super('Email' => kwargs[:email], 'Password Hash' => self.class.password_hash(kwargs[:password]), 'Access Token' => self.class.next_access_token)
62
- else
63
- super
64
- end
50
+ def valid_password?(password)
51
+ BCrypt::Password.new(password_hash) == password
65
52
  end
66
- end
67
53
 
68
- def valid_password?(password)
69
- BCrypt::Password.new(password_hash) == password
70
- end
54
+ def password_hash
55
+ self['Password Hash']
56
+ end
71
57
 
72
- def password_hash
73
- self['Password Hash']
74
- end
58
+ def oauth_session
59
+ ensure_access_token!
60
+
61
+ {
62
+ access_token: self['Access Token'],
63
+ scope: :user,
64
+ token_type: :bearer,
65
+ expires_in: 31_536_000 # 1 year
66
+ }
67
+ end
75
68
 
76
- def oauth_session
77
- { access_token: self['Access Token'], scope: :user, refresh_token: '', token_type: :bearer, expires_in: 60_000 }
69
+ def ensure_access_token!
70
+ unless self['Access Token']
71
+ self['Access Token'] = User.next_access_token
72
+ save
73
+ end
74
+ end
78
75
  end
79
76
  end
80
77
  end
@@ -22,6 +22,10 @@ module AppRail
22
22
  request.env['HTTP_AUTHORIZATION']
23
23
  end
24
24
 
25
+ def oauth_client_id
26
+ ENV.fetch('OAUTH_CLIENT_ID')
27
+ end
28
+
25
29
  def authenticate!
26
30
  halt 401 unless current_user
27
31
  end
@@ -46,6 +46,8 @@ module AppRail
46
46
  # Allowing the routes to use `authenticate!` and `current_user`
47
47
  helpers AppRail::Airtable::AuthenticationHelpers
48
48
 
49
+ sign_in_route(name)
50
+ sign_out_route(name)
49
51
  resources(name, only: only)
50
52
 
51
53
  return unless block_given?
@@ -64,6 +66,28 @@ module AppRail
64
66
  update_route(name, authenticated_route?) if only.include?(:update)
65
67
  end
66
68
 
69
+ def self.sign_in_route(name)
70
+ post "/#{name}/session" do
71
+ halt [401, { error: 'Invalid client_id' }.to_json] unless params['client_id'] == oauth_client_id
72
+
73
+ resource = name.classify_constantize.authenticate_by_params(params)
74
+ halt [401, { error: 'Invalid credentials' }.to_json] unless resource
75
+
76
+ resource.oauth_session.to_json
77
+ end
78
+ end
79
+
80
+ def self.sign_out_route(name)
81
+ delete "/#{name}/session" do
82
+ authenticate!
83
+ current_user.access_token = nil
84
+ current_user.save
85
+
86
+ # Assume that the client will reload and trigger a 401
87
+ [].to_json
88
+ end
89
+ end
90
+
67
91
  def self.index_route(name, authenticated_route)
68
92
  get "/#{name}" do
69
93
  authenticate! if authenticated_route
@@ -2,6 +2,6 @@
2
2
 
3
3
  module AppRail
4
4
  module Airtable
5
- VERSION = '0.4.5'
5
+ VERSION = '0.4.8'
6
6
  end
7
7
  end
@@ -3,10 +3,12 @@
3
3
  source 'https://rubygems.org'
4
4
  git_source(:github) { |repo| "https://github.com/#{repo}.git" }
5
5
 
6
- ruby '2.7.4'
6
+ ruby '3.1.2'
7
7
 
8
- gem 'app_rail-airtable', '~> 0.4.0'
8
+ gem 'app_rail-airtable'
9
9
  gem 'app_rail-steps'
10
+ gem 'sinatra', '~> 3.0', '>= 3.0.2'
11
+ gem 'puma'
10
12
 
11
13
  group :development do
12
14
  gem 'dotenv'
@@ -0,0 +1,8 @@
1
+ # frozen_string_literal: true
2
+
3
+ ENV['RACK_ENV'] ||= 'development'
4
+
5
+ require 'dotenv/load' if ENV['RACK_ENV'] == 'development'
6
+
7
+ require 'bundler'
8
+ Bundler.require(:default, ENV['RACK_ENV'].to_sym)
@@ -1,13 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  $stdout.sync = true
4
-
5
- ENV['RACK_ENV'] ||= 'development'
6
- require 'dotenv/load' if ENV['RACK_ENV'] == 'development'
7
- require 'bundler'
8
- Bundler.require(:default, ENV['RACK_ENV'].to_sym)
9
-
10
- require 'dotenv/load' if ENV['RACK_ENV'] == 'development'
11
-
4
+ require './boot'
12
5
  require './lib/server'
13
6
  run Server
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: app_rail-airtable
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.5
4
+ version: 0.4.8
5
5
  platform: ruby
6
6
  authors:
7
7
  - Matt Brooke-Smith
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-04-27 00:00:00.000000000 Z
11
+ date: 2022-10-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -187,6 +187,7 @@ files:
187
187
  - templates/project/.gitignore
188
188
  - templates/project/Gemfile
189
189
  - templates/project/app.json
190
+ - templates/project/boot.rb
190
191
  - templates/project/config.ru
191
192
  - templates/project/lib/server.rb.tt
192
193
  - templates/project/spec/server_spec.rb.tt
@@ -212,7 +213,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
212
213
  - !ruby/object:Gem::Version
213
214
  version: '0'
214
215
  requirements: []
215
- rubygems_version: 3.1.6
216
+ rubygems_version: 3.3.7
216
217
  signing_key:
217
218
  specification_version: 4
218
219
  summary: Gem to help building App Rail servers using Airtable as a backend