clerk-rails 0.1.12 → 0.1.13
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/app/controllers/clerk/application_controller.rb +0 -11
- data/config/initializers/add_application_helpers.rb +4 -2
- data/config/routes.rb +0 -1
- data/lib/clerk-rails.rb +1 -1
- data/lib/clerk/engine.rb +32 -8
- data/lib/clerk/helpers.rb +35 -23
- data/lib/clerk/tunnel.rb +5 -2
- data/lib/clerk/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: cafada07a7c556113d90ac25bde235e5cb482c59985eca672597d04bee71f52c
|
4
|
+
data.tar.gz: 373a270635cc36b2c894ea2824e47aa32d9deffe1cc105c69bb5543aafbb9dae
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 745d78b935c69a216c814b32187a3429893d394320d57a24dc77ab8ddae3cb1a36cfc07fc0b7d37c0433d857f07d2d609a59486b38e21ba024336f17a1d2a19b
|
7
|
+
data.tar.gz: aa9781a39510692c074b20fe30304f36e74e3781eabbbbaf1ec5b8cca046719e8592d355d1a398e085b316e17eb50e1a221ed79c2facd7b041f8321818cd0fe2
|
@@ -1,15 +1,4 @@
|
|
1
1
|
module Clerk
|
2
2
|
class ApplicationController < ActionController::Base
|
3
|
-
def remote_cookie_accessor
|
4
|
-
# TODO: Only drop cookie if signature verifies
|
5
|
-
# TODO: Hide route entirely if client doesn't use remote cookies
|
6
|
-
cookie_domain = (request.host.include?(".") ? ".#{request.host}" : nil)
|
7
|
-
if params[:value].blank?
|
8
|
-
cookies.delete :clerk_session, domain: cookie_domain
|
9
|
-
else
|
10
|
-
cookies[:clerk_session] = {value: params[:value], domain: cookie_domain, expires: 20.years}
|
11
|
-
end
|
12
|
-
redirect_to params[:redirect]
|
13
|
-
end
|
14
3
|
end
|
15
4
|
end
|
@@ -1,2 +1,4 @@
|
|
1
|
-
::ActionController::Base.send :helper, Clerk::Helpers
|
2
|
-
::ActionController::Base.send :include, Clerk::Helpers
|
1
|
+
::ActionController::Base.send :helper, Clerk::Helpers::View
|
2
|
+
::ActionController::Base.send :include, Clerk::Helpers::Controller
|
3
|
+
::ActionController::Base.send :helper, Clerk::Helpers::ViewAndController
|
4
|
+
::ActionController::Base.send :include, Clerk::Helpers::ViewAndController
|
data/config/routes.rb
CHANGED
data/lib/clerk-rails.rb
CHANGED
data/lib/clerk/engine.rb
CHANGED
@@ -1,5 +1,8 @@
|
|
1
1
|
module Clerk
|
2
2
|
class Engine < ::Rails::Engine
|
3
|
+
isolate_namespace Clerk
|
4
|
+
engine_name "clerk"
|
5
|
+
|
3
6
|
config.before_configuration do
|
4
7
|
if Rails.env.development?
|
5
8
|
require 'dotenv'
|
@@ -7,19 +10,20 @@ module Clerk
|
|
7
10
|
end
|
8
11
|
|
9
12
|
if Clerk.key.nil?
|
10
|
-
raise "Clerk is installed but not configured.
|
13
|
+
raise "Clerk is installed but not configured. Set your CLERK_KEY as an environment variable."
|
11
14
|
end
|
12
15
|
|
13
16
|
begin
|
14
17
|
config_data = Clerk.api.get('/api/environment').data
|
15
18
|
Clerk.configure do |config|
|
16
|
-
config.accounts_host
|
17
|
-
config.app_host
|
18
|
-
config.cipher_key
|
19
|
-
config.database_url
|
20
|
-
config.
|
21
|
-
config.
|
22
|
-
config.
|
19
|
+
config.accounts_host = config_data[:ACCOUNTS_HOST]
|
20
|
+
config.app_host = config_data[:APP_HOST]
|
21
|
+
config.cipher_key = config_data[:CIPHER_KEY]
|
22
|
+
config.database_url = config_data[:DATABASE_URL]
|
23
|
+
config.email_address_verification = config_data[:EMAIL_ADDRESS_VERIFICATION]
|
24
|
+
config.ngrok_authtoken = config_data[:NGROK_AUTHTOKEN]
|
25
|
+
config.tunnel_cert = config_data[:TUNNEL_CERT]
|
26
|
+
config.tunnel_key = config_data[:TUNNEL_KEY]
|
23
27
|
end
|
24
28
|
rescue => e
|
25
29
|
raise "Clerk could not be loaded. #{e} #{config_data}"
|
@@ -30,5 +34,25 @@ module Clerk
|
|
30
34
|
Clerk::Tunnel.start!
|
31
35
|
end
|
32
36
|
end
|
37
|
+
|
38
|
+
accounts_routes = {
|
39
|
+
sign_out: "/sign_out",
|
40
|
+
sign_in: "/",
|
41
|
+
sign_up: "/sign_up",
|
42
|
+
verify_email_address: "/verify_email_address",
|
43
|
+
}
|
44
|
+
|
45
|
+
|
46
|
+
initializer 'clerk.configuration' do |app|
|
47
|
+
app.routes.append do
|
48
|
+
mount Clerk::Engine => "/"
|
49
|
+
|
50
|
+
accounts_routes.each do |k, v|
|
51
|
+
direct k do
|
52
|
+
"#{Clerk.accounts_url}#{v}"
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
33
57
|
end
|
34
58
|
end
|
data/lib/clerk/helpers.rb
CHANGED
@@ -3,35 +3,47 @@
|
|
3
3
|
# https://stackoverflow.com/questions/29636334/a-copy-of-xxx-has-been-removed-from-the-module-tree-but-is-still-active
|
4
4
|
module Clerk
|
5
5
|
module Helpers
|
6
|
-
|
7
|
-
if cookies[:clerk_session]
|
8
|
-
@clerk_current_account ||= SessionToken.find_account(
|
9
|
-
cookie: cookies[:clerk_session]
|
10
|
-
)
|
11
|
-
elsif request.headers['Authorization']
|
12
|
-
token = request.headers['Authorization'].slice(7..-1)
|
13
|
-
@clerk_current_account ||= SessionToken.find_account(
|
14
|
-
cookie: token
|
15
|
-
)
|
16
|
-
else
|
17
|
-
return nil
|
18
|
-
end
|
6
|
+
module View
|
19
7
|
end
|
20
8
|
|
21
|
-
|
22
|
-
|
9
|
+
module Controller
|
10
|
+
def authenticate_account!
|
11
|
+
if account_signed_in?
|
12
|
+
if Clerk.config.email_address_verification == "forced" and !current_account.verified_email_address
|
13
|
+
redirect_to verify_email_address_url and return
|
14
|
+
end
|
15
|
+
else
|
16
|
+
redirect_to sign_in_url and return
|
17
|
+
end
|
18
|
+
end
|
23
19
|
end
|
24
20
|
|
25
|
-
|
26
|
-
|
27
|
-
|
21
|
+
module ViewAndController
|
22
|
+
def account_signed_in?
|
23
|
+
!current_account.nil?
|
24
|
+
end
|
28
25
|
|
29
|
-
|
30
|
-
|
31
|
-
|
26
|
+
def current_account
|
27
|
+
@clerk_current_account ||= begin
|
28
|
+
if cookies[:clerk_session]
|
29
|
+
SessionToken.find_account(
|
30
|
+
cookie: cookies[:clerk_session]
|
31
|
+
)
|
32
|
+
elsif request.headers['Authorization']
|
33
|
+
token = request.headers['Authorization'].slice(7..-1)
|
34
|
+
SessionToken.find_account(
|
35
|
+
cookie: token
|
36
|
+
)
|
37
|
+
else
|
38
|
+
nil
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
32
42
|
|
33
|
-
|
34
|
-
"#{Clerk.accounts_url}/add_card?account_id=#{account_id}&redirect_path=#{redirect_path}"
|
43
|
+
# def clerk_add_card_path(account_id:, redirect_path:)
|
44
|
+
# "#{Clerk.accounts_url}/add_card?account_id=#{account_id}&redirect_path=#{redirect_path}"
|
45
|
+
# end
|
35
46
|
end
|
47
|
+
|
36
48
|
end
|
37
49
|
end
|
data/lib/clerk/tunnel.rb
CHANGED
@@ -65,6 +65,8 @@ module Clerk
|
|
65
65
|
end
|
66
66
|
|
67
67
|
File.delete(ngrok_zip_path)
|
68
|
+
|
69
|
+
puts "=> [Clerk] Setup done."
|
68
70
|
end
|
69
71
|
|
70
72
|
def self.save_tunnel_cert_locally!
|
@@ -75,13 +77,12 @@ module Clerk
|
|
75
77
|
|
76
78
|
def self.start!
|
77
79
|
if Clerk.config.tunnel_cert == nil || Clerk.config.tunnel_key == nil
|
78
|
-
raise "=> Sorry, your dev certificate isn't ready yet. It may take up to 30 minutes to create."
|
80
|
+
raise "=> [Clerk] Sorry, your dev certificate isn't ready yet. It may take up to 30 minutes to create."
|
79
81
|
end
|
80
82
|
|
81
83
|
save_tunnel_cert_locally!
|
82
84
|
|
83
85
|
setup_ngrok! unless ngrok_ready?
|
84
|
-
puts "=> [Clerk] Setup done."
|
85
86
|
|
86
87
|
self.patch_rack_requests
|
87
88
|
|
@@ -183,6 +184,8 @@ module Clerk
|
|
183
184
|
fetch_urls
|
184
185
|
end
|
185
186
|
|
187
|
+
puts " ngrok logging to #{@params[:log].path}"
|
188
|
+
|
186
189
|
@status = :running
|
187
190
|
@ngrok_url.gsub("tls", "https")
|
188
191
|
end
|
data/lib/clerk/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: clerk-rails
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.13
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Clerk
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-
|
11
|
+
date: 2019-03-08 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|