app_rail-airtable 0.2.9 → 0.2.10
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +1 -1
- data/lib/app_rail/airtable/authenticatable.rb +47 -0
- data/lib/app_rail/airtable/authentication_helpers.rb +27 -0
- data/lib/app_rail/airtable/sinatra.rb +2 -2
- data/lib/app_rail/airtable/version.rb +1 -1
- data/lib/app_rail/airtable.rb +2 -1
- metadata +3 -2
- data/lib/app_rail/airtable/authentication_record.rb +0 -27
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3e57f8d279b01f1a7672be43fce5dda36da9df13bc3152399646f5be729d522c
|
4
|
+
data.tar.gz: 7928368ae9d1b4edfd75c651af688be2aa0e7697f31fd5c87afb1a9e96e3945c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5eef1c52f304ffe1b0050ff5a7278e47c825dce1e7e08a7af69550894070e23a465dc719fce7dddabfa06de9336f2b63d230685098d09a5c02711b17fe43394d
|
7
|
+
data.tar.gz: e3629a453d333d78aac608f45ac04b303b27c636f4350fb0f5c2b42c739756a274faabd55a08278b0cc445a5777f62ae57431acea477dae20575ff1cfac53e59
|
data/Gemfile.lock
CHANGED
@@ -0,0 +1,47 @@
|
|
1
|
+
require 'bcrypt'
|
2
|
+
require 'securerandom'
|
3
|
+
|
4
|
+
module AppRail
|
5
|
+
module Airtable
|
6
|
+
module Authenticatable
|
7
|
+
include BCrypt
|
8
|
+
|
9
|
+
def self.included(klass)
|
10
|
+
klass.extend(ClassMethods)
|
11
|
+
end
|
12
|
+
|
13
|
+
module ClassMethods
|
14
|
+
def create(email:, password:)
|
15
|
+
user = User.new("Email" => email, "Password Hash" => password_hash(password), "Access Token" => access_token)
|
16
|
+
user.create
|
17
|
+
user
|
18
|
+
end
|
19
|
+
|
20
|
+
def create_session_as_json(email:, password:)
|
21
|
+
user = find_by_email_and_password(email, password)
|
22
|
+
user&.oauth_session
|
23
|
+
end
|
24
|
+
|
25
|
+
def find_by_email_and_password(email, password)
|
26
|
+
all(filter: "AND({Email} = \"#{email}\",{Password Hash} = \"#{password_hash(password)}\")").first
|
27
|
+
end
|
28
|
+
|
29
|
+
def find_by_access_token(access_token)
|
30
|
+
all(filter: "{Access Token} = \"#{access_token}\"").first
|
31
|
+
end
|
32
|
+
|
33
|
+
def password_hash(password)
|
34
|
+
BCrypt::Password.create(password)
|
35
|
+
end
|
36
|
+
|
37
|
+
def access_token
|
38
|
+
SecureRandom.hex
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
def oauth_session
|
43
|
+
{ access_token: self["Access Token"], scope: :user, refresh_token: "", token_type: :bearer, expires_in: 60000 }
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
module AppRail
|
2
|
+
module Airtable
|
3
|
+
module AuthenticationHelpers
|
4
|
+
def current_user
|
5
|
+
@current_user ||= find_current_user
|
6
|
+
end
|
7
|
+
|
8
|
+
def find_current_user
|
9
|
+
authorization_header && bearer_token ? User.find_by_access_token(bearer_token) : nil
|
10
|
+
end
|
11
|
+
|
12
|
+
def bearer_token
|
13
|
+
authorization_values = authorization_header.split(" ")
|
14
|
+
return nil unless authorization_values.count > 1
|
15
|
+
authorization_values[1]
|
16
|
+
end
|
17
|
+
|
18
|
+
def authorization_header
|
19
|
+
request.env["HTTP_AUTHORIZATION"]
|
20
|
+
end
|
21
|
+
|
22
|
+
def authenticate!
|
23
|
+
halt 401 unless current_user
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
@@ -31,7 +31,7 @@ module AppRail
|
|
31
31
|
JSON.parse(request.body.read)
|
32
32
|
end
|
33
33
|
|
34
|
-
def
|
34
|
+
def params_and_body_as_json
|
35
35
|
request_body_as_json.merge(params)
|
36
36
|
end
|
37
37
|
end
|
@@ -61,7 +61,7 @@ module AppRail
|
|
61
61
|
def self.create_route(name, authenticated)
|
62
62
|
post "/#{name.to_s}" do
|
63
63
|
authenticate! if authenticated
|
64
|
-
as_json = name.classify_constantize.create_as_json(current_user: authenticated ? current_user : nil, params:
|
64
|
+
as_json = name.classify_constantize.create_as_json(current_user: authenticated ? current_user : nil, params: params_and_body_as_json)
|
65
65
|
[201, as_json.to_json]
|
66
66
|
end
|
67
67
|
end
|
data/lib/app_rail/airtable.rb
CHANGED
@@ -1,7 +1,8 @@
|
|
1
1
|
require "app_rail/airtable/version"
|
2
2
|
require "app_rail/airtable/string_ext"
|
3
3
|
require "app_rail/airtable/application_record"
|
4
|
-
require "app_rail/airtable/
|
4
|
+
require "app_rail/airtable/authenticatable"
|
5
|
+
require "app_rail/airtable/authentication_helpers"
|
5
6
|
require "app_rail/airtable/sinatra"
|
6
7
|
require "app_rail/airtable/generator"
|
7
8
|
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: app_rail-airtable
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.10
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Matt Brooke-Smith
|
@@ -130,7 +130,8 @@ files:
|
|
130
130
|
- bin/setup
|
131
131
|
- lib/app_rail/airtable.rb
|
132
132
|
- lib/app_rail/airtable/application_record.rb
|
133
|
-
- lib/app_rail/airtable/
|
133
|
+
- lib/app_rail/airtable/authenticatable.rb
|
134
|
+
- lib/app_rail/airtable/authentication_helpers.rb
|
134
135
|
- lib/app_rail/airtable/generator.rb
|
135
136
|
- lib/app_rail/airtable/sinatra.rb
|
136
137
|
- lib/app_rail/airtable/string_ext.rb
|
@@ -1,27 +0,0 @@
|
|
1
|
-
require 'bcrypt'
|
2
|
-
|
3
|
-
module AppRail
|
4
|
-
module Airtable
|
5
|
-
class AuthenticationRecord < ApplicationRecord
|
6
|
-
include BCrypt
|
7
|
-
airtable_attr "Email", "Password Hash", "Access Token"
|
8
|
-
|
9
|
-
def self.create_session_as_json(email:, password:)
|
10
|
-
user = find_by_email_and_password(email, Password.create(password))
|
11
|
-
user&.oauth_session
|
12
|
-
end
|
13
|
-
|
14
|
-
def self.find_by_email_and_password(email, password_hash)
|
15
|
-
all(filter: "AND({Email} = \"#{email}\",{Password Hash} = \"#{password_hash}\")").first
|
16
|
-
end
|
17
|
-
|
18
|
-
def self.find_by_access_token(access_token)
|
19
|
-
all(filter: "{Access Token} = \"#{access_token}\"").first
|
20
|
-
end
|
21
|
-
|
22
|
-
def oauth_session
|
23
|
-
{ access_token: self["Access Token"], scope: :user, refresh_token: "", token_type: :bearer, expires_in: 60000 }
|
24
|
-
end
|
25
|
-
end
|
26
|
-
end
|
27
|
-
end
|