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 +4 -4
- data/CHANGELOG.md +4 -0
- data/Gemfile.lock +1 -1
- data/lib/app_rail/airtable/authenticatable.rb +15 -10
- data/lib/app_rail/airtable/sinatra.rb +22 -0
- data/lib/app_rail/airtable/version.rb +1 -1
- data/templates/project/boot.rb +8 -0
- data/templates/project/config.ru +1 -8
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3e4126f9d575a705e24ba998e9adb2ecd3dc95c567e13668a733b246fe9401fc
|
4
|
+
data.tar.gz: 58b0c53b463db9b7689c580b1fc5d7284c0d72ddf10e51f5eeeee1e63a65fc65
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f5969fbe95e911778f4b44104137c6ffe13163e55ea0a57aa13d6b03746ea4ef00daec15b6af9eb1a1c5d58fd2da5903e6cc2e90c71d7cd222dbacfa69b9f11f
|
7
|
+
data.tar.gz: b73be3571e4711e835b2a287a38132e8b38c071d433672de505ccce12c2e1658206fb35fdf4985dcc7ef6b32853cf69996e81589ac50fbfec431b6fed261cfe1
|
data/CHANGELOG.md
CHANGED
data/Gemfile.lock
CHANGED
@@ -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
|
-
|
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
|
data/templates/project/config.ru
CHANGED
@@ -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.
|
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-
|
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
|