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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 9f72756f43933b36d6bfb6ef4cab2e0502ce66016736245e9c8c2aac0de2efab
4
- data.tar.gz: a8b4f069a37a4cfb0011dcc36ff83118537bcfe589e28105c298abaee96ab0a1
3
+ metadata.gz: cafada07a7c556113d90ac25bde235e5cb482c59985eca672597d04bee71f52c
4
+ data.tar.gz: 373a270635cc36b2c894ea2824e47aa32d9deffe1cc105c69bb5543aafbb9dae
5
5
  SHA512:
6
- metadata.gz: d5fba368e3b1113fc060cb89329ed71d8376526f2efc78a45baecfb820202811d4578ce3a951e5acb241f8654ce74c2cc31486aacbc0c7b65d254aeebcaafb0a
7
- data.tar.gz: 32f1ae8f3a00f3df6150e6658df3616d07c5810bfa7b0430d6d746da5eafdfab89984acdb377d1acdfda2697757a227788eeb0013c26e51e3ea9c6abe8bd18e9
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
@@ -1,3 +1,2 @@
1
1
  Clerk::Engine.routes.draw do
2
- get 'remote_cookie_accessor', to: 'clerk/application#remote_cookie_accessor'
3
2
  end
@@ -72,7 +72,7 @@ module Clerk
72
72
  :app_host,
73
73
  :cipher_key,
74
74
  :database_url,
75
- :last_account,
75
+ :email_address_verification,
76
76
  :ngrok_authtoken,
77
77
  :tunnel_cert,
78
78
  :tunnel_key
@@ -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. Add your CLERK_KEY to the application root."
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 = config_data[:ACCOUNTS_HOST]
17
- config.app_host = config_data[:APP_HOST]
18
- config.cipher_key = config_data[:CIPHER_KEY]
19
- config.database_url = config_data[:DATABASE_URL]
20
- config.ngrok_authtoken = config_data[:NGROK_AUTHTOKEN]
21
- config.tunnel_cert = config_data[:TUNNEL_CERT]
22
- config.tunnel_key = config_data[:TUNNEL_KEY]
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
@@ -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
- def current_account
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
- def clerk_sign_out_path
22
- "#{Clerk.accounts_url}/sign_out"
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
- def clerk_sign_in_path
26
- "#{Clerk.accounts_url}"
27
- end
21
+ module ViewAndController
22
+ def account_signed_in?
23
+ !current_account.nil?
24
+ end
28
25
 
29
- def clerk_sign_up_path
30
- "#{Clerk.accounts_url}/sign_up"
31
- end
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
- def clerk_add_card_path(account_id:, redirect_path:)
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
@@ -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
@@ -1,3 +1,3 @@
1
1
  module Clerk
2
- VERSION = '0.1.12'
2
+ VERSION = '0.1.13'
3
3
  end
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.12
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-02-26 00:00:00.000000000 Z
11
+ date: 2019-03-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails