app_rail-airtable 0.4.5 → 0.4.6

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: 3e4126f9d575a705e24ba998e9adb2ecd3dc95c567e13668a733b246fe9401fc
4
+ data.tar.gz: 58b0c53b463db9b7689c580b1fc5d7284c0d72ddf10e51f5eeeee1e63a65fc65
5
5
  SHA512:
6
- metadata.gz: 05efe59ea2696590acf285e0c641f5c1ef42961f42b46aaed2c316d449ef797e06d3f9f15a14488ee4385e29028609bac35e67dcca41fdb6fa44edc35f51a346
7
- data.tar.gz: e28840bfed651fee92759cf4102157b7a45472c0bb87b7a0d1e8bafe81afce034b2e8db3e6090045063b01d3c990e8e369ce8d682c5f7fc988e776801968cd0f
6
+ metadata.gz: f5969fbe95e911778f4b44104137c6ffe13163e55ea0a57aa13d6b03746ea4ef00daec15b6af9eb1a1c5d58fd2da5903e6cc2e90c71d7cd222dbacfa69b9f11f
7
+ data.tar.gz: b73be3571e4711e835b2a287a38132e8b38c071d433672de505ccce12c2e1658206fb35fdf4985dcc7ef6b32853cf69996e81589ac50fbfec431b6fed261cfe1
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.6)
5
5
  activesupport
6
6
  airrecord
7
7
  app_rail-steps
@@ -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
@@ -74,7 +65,21 @@ module AppRail
74
65
  end
75
66
 
76
67
  def oauth_session
77
- { access_token: self['Access Token'], scope: :user, refresh_token: '', token_type: :bearer, expires_in: 60_000 }
68
+ ensure_access_token!
69
+
70
+ {
71
+ access_token: self['Access Token'],
72
+ scope: :user,
73
+ token_type: :bearer,
74
+ expires_in: 31_536_000 # 1 year
75
+ }
76
+ end
77
+
78
+ def ensure_access_token!
79
+ unless self['Access Token']
80
+ self['Access Token'] = User.next_access_token
81
+ save
82
+ end
78
83
  end
79
84
  end
80
85
  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,26 @@ 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
+ resource = name.classify_constantize.authenticate_by_params(params)
72
+ halt 401 unless resource
73
+
74
+ resource.oauth_session.to_json
75
+ end
76
+ end
77
+
78
+ def self.sign_out_route(name)
79
+ delete "/#{name}/session" do
80
+ authenticate!
81
+ current_user.access_token = nil
82
+ current_user.save
83
+
84
+ # Assume that the client will reload and trigger a 401
85
+ [].to_json
86
+ end
87
+ end
88
+
67
89
  def self.index_route(name, authenticated_route)
68
90
  get "/#{name}" do
69
91
  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.6'
6
6
  end
7
7
  end
@@ -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.6
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-05-02 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