castle_devise 0.6.0 → 0.7.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.github/workflows/lint.yml +1 -1
- data/.github/workflows/specs.yml +1 -2
- data/.tool-versions +1 -0
- data/CHANGELOG.md +11 -1
- data/Gemfile.lock +75 -80
- data/README.md +16 -24
- data/lib/castle_devise/configuration.rb +3 -3
- data/lib/castle_devise/helpers/castle_devise.js +48 -0
- data/lib/castle_devise/helpers/castle_helper.rb +33 -13
- data/lib/castle_devise/version.rb +1 -1
- data/mise.toml +11 -0
- metadata +5 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: ec99e18ff024ed0a67da899ebb6ecd0feca90f4f4a9e9ecf482195f99473c536
|
|
4
|
+
data.tar.gz: 1936cca9eb03a1f6a70680337f9513f266fe09493d1886881ccd3d8be8a3c759
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: ba9db9541573aa3ce7e7dba634bae8756303f337327bd96631d73b0055fbb6159d311ba668a9ae6828392336cf2aeec49702e827134f6ba9a650095b67af9de2
|
|
7
|
+
data.tar.gz: da1ee7ab23bdd7db7b9a2975d7becd1d2dd10ad56667db657355ed49126975fabba059342f2975ae6e536fedd9fdb7479cddce81a17bb50c2d26e299cd6c3c20
|
data/.github/workflows/lint.yml
CHANGED
data/.github/workflows/specs.yml
CHANGED
|
@@ -45,7 +45,7 @@ jobs:
|
|
|
45
45
|
- ruby: "4.0"
|
|
46
46
|
rails: "8.1"
|
|
47
47
|
steps:
|
|
48
|
-
- uses: actions/checkout@
|
|
48
|
+
- uses: actions/checkout@v5
|
|
49
49
|
- name: Set up Ruby ${{ matrix.ruby }}
|
|
50
50
|
uses: ruby/setup-ruby@v1
|
|
51
51
|
with:
|
|
@@ -59,7 +59,6 @@ jobs:
|
|
|
59
59
|
- name: Run specs
|
|
60
60
|
env:
|
|
61
61
|
BUNDLE_GEMFILE: gemfiles/rails_${{ matrix.rails }}.gemfile
|
|
62
|
-
CASTLE_API_SECRET: ${{ secrets.CASTLE_API_SECRET }}
|
|
63
62
|
run: |
|
|
64
63
|
bundle exec rake
|
|
65
64
|
- name: Simplecov Report
|
data/.tool-versions
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
ruby 3.4.10
|
data/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,15 @@
|
|
|
2
2
|
|
|
3
3
|
## [Unreleased][main]
|
|
4
4
|
|
|
5
|
+
## [0.7.0] - 2026-09-07
|
|
6
|
+
- Drop `cdn.castle.io`; load `castle.umd.js` from `/vendor/castle-js` via `castle_javascript_tag`
|
|
7
|
+
- Seed `window.Castle` before a UMD script so 3.x (`name: @castleio/castle-js`) attaches to the same global
|
|
8
|
+
- Support `@castleio/castle-js` 2.x (`injectTokenOnSubmit` / `createRequestToken`) and 3.x (`configure({ pk })` + `createRequestToken`)
|
|
9
|
+
- Add `publishable_key` configuration and drop `app_id`
|
|
10
|
+
- Bump development Gemfile.lock dependencies, including Rails 8.1.3.1, `castle-rb` 9.3.0, Standard 1.56, and SimpleCov 1.2
|
|
11
|
+
- Pin Ruby 3.4.10 via `.tool-versions` and add `mise.toml` task aliases
|
|
12
|
+
- Use `actions/checkout@v5` in CI
|
|
13
|
+
|
|
5
14
|
## [0.6.0] - 2026-05-25
|
|
6
15
|
- Add support for Rails 8.1
|
|
7
16
|
- Add support for Devise 5
|
|
@@ -48,7 +57,8 @@
|
|
|
48
57
|
|
|
49
58
|
- Initial release
|
|
50
59
|
|
|
51
|
-
[main]: https://github.com/castle/castle_devise/compare/v0.
|
|
60
|
+
[main]: https://github.com/castle/castle_devise/compare/v0.7.0...HEAD
|
|
61
|
+
[0.7.0]: https://github.com/castle/castle_devise/compare/v0.6.0...v0.7.0
|
|
52
62
|
[0.6.0]: https://github.com/castle/castle_devise/compare/v0.5.0...v0.6.0
|
|
53
63
|
[0.5.0]: https://github.com/castle/castle_devise/compare/v0.4.3...v0.5.0
|
|
54
64
|
[0.4.3]: https://github.com/castle/castle_devise/compare/v0.4.2...v0.4.3
|
data/Gemfile.lock
CHANGED
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
GIT
|
|
2
2
|
remote: https://github.com/castle/castle-ruby.git
|
|
3
|
-
revision:
|
|
3
|
+
revision: 09f37c6d68754c229ade675513c4abe473d69ad2
|
|
4
4
|
branch: develop
|
|
5
5
|
specs:
|
|
6
|
-
castle-rb (9.
|
|
6
|
+
castle-rb (9.3.0)
|
|
7
7
|
base64 (~> 0.2)
|
|
8
8
|
|
|
9
9
|
PATH
|
|
10
10
|
remote: .
|
|
11
11
|
specs:
|
|
12
|
-
castle_devise (0.
|
|
12
|
+
castle_devise (0.7.0)
|
|
13
13
|
activesupport (>= 6.0)
|
|
14
14
|
castle-rb (>= 7.2, < 10.0)
|
|
15
15
|
devise (>= 4.3.0, < 6.0)
|
|
@@ -17,16 +17,16 @@ PATH
|
|
|
17
17
|
GEM
|
|
18
18
|
remote: https://rubygems.org/
|
|
19
19
|
specs:
|
|
20
|
-
actionmailer (8.1.3)
|
|
21
|
-
actionpack (= 8.1.3)
|
|
22
|
-
actionview (= 8.1.3)
|
|
23
|
-
activejob (= 8.1.3)
|
|
24
|
-
activesupport (= 8.1.3)
|
|
20
|
+
actionmailer (8.1.3.1)
|
|
21
|
+
actionpack (= 8.1.3.1)
|
|
22
|
+
actionview (= 8.1.3.1)
|
|
23
|
+
activejob (= 8.1.3.1)
|
|
24
|
+
activesupport (= 8.1.3.1)
|
|
25
25
|
mail (>= 2.8.0)
|
|
26
26
|
rails-dom-testing (~> 2.2)
|
|
27
|
-
actionpack (8.1.3)
|
|
28
|
-
actionview (= 8.1.3)
|
|
29
|
-
activesupport (= 8.1.3)
|
|
27
|
+
actionpack (8.1.3.1)
|
|
28
|
+
actionview (= 8.1.3.1)
|
|
29
|
+
activesupport (= 8.1.3.1)
|
|
30
30
|
nokogiri (>= 1.8.5)
|
|
31
31
|
rack (>= 2.2.4)
|
|
32
32
|
rack-session (>= 1.0.1)
|
|
@@ -34,22 +34,22 @@ GEM
|
|
|
34
34
|
rails-dom-testing (~> 2.2)
|
|
35
35
|
rails-html-sanitizer (~> 1.6)
|
|
36
36
|
useragent (~> 0.16)
|
|
37
|
-
actionview (8.1.3)
|
|
38
|
-
activesupport (= 8.1.3)
|
|
37
|
+
actionview (8.1.3.1)
|
|
38
|
+
activesupport (= 8.1.3.1)
|
|
39
39
|
builder (~> 3.1)
|
|
40
40
|
erubi (~> 1.11)
|
|
41
41
|
rails-dom-testing (~> 2.2)
|
|
42
42
|
rails-html-sanitizer (~> 1.6)
|
|
43
|
-
activejob (8.1.3)
|
|
44
|
-
activesupport (= 8.1.3)
|
|
43
|
+
activejob (8.1.3.1)
|
|
44
|
+
activesupport (= 8.1.3.1)
|
|
45
45
|
globalid (>= 0.3.6)
|
|
46
|
-
activemodel (8.1.3)
|
|
47
|
-
activesupport (= 8.1.3)
|
|
48
|
-
activerecord (8.1.3)
|
|
49
|
-
activemodel (= 8.1.3)
|
|
50
|
-
activesupport (= 8.1.3)
|
|
46
|
+
activemodel (8.1.3.1)
|
|
47
|
+
activesupport (= 8.1.3.1)
|
|
48
|
+
activerecord (8.1.3.1)
|
|
49
|
+
activemodel (= 8.1.3.1)
|
|
50
|
+
activesupport (= 8.1.3.1)
|
|
51
51
|
timeout (>= 0.4.0)
|
|
52
|
-
activesupport (8.1.3)
|
|
52
|
+
activesupport (8.1.3.1)
|
|
53
53
|
base64
|
|
54
54
|
bigdecimal
|
|
55
55
|
concurrent-ruby (~> 1.0, >= 1.3.1)
|
|
@@ -71,12 +71,12 @@ GEM
|
|
|
71
71
|
builder (3.3.0)
|
|
72
72
|
byebug (13.0.0)
|
|
73
73
|
reline (>= 0.6.0)
|
|
74
|
-
concurrent-ruby (1.3.
|
|
74
|
+
concurrent-ruby (1.3.8)
|
|
75
75
|
connection_pool (3.0.2)
|
|
76
76
|
crack (1.0.1)
|
|
77
77
|
bigdecimal
|
|
78
78
|
rexml
|
|
79
|
-
crass (1.0.
|
|
79
|
+
crass (1.0.7)
|
|
80
80
|
date (3.5.1)
|
|
81
81
|
devise (5.0.4)
|
|
82
82
|
bcrypt (~> 3.0)
|
|
@@ -85,29 +85,28 @@ GEM
|
|
|
85
85
|
responders
|
|
86
86
|
warden (~> 1.2.3)
|
|
87
87
|
diff-lcs (1.6.2)
|
|
88
|
-
docile (1.4.1)
|
|
89
88
|
drb (2.2.3)
|
|
90
|
-
erb (6.0.
|
|
89
|
+
erb (6.0.7)
|
|
91
90
|
erubi (1.13.1)
|
|
92
|
-
globalid (1.
|
|
91
|
+
globalid (1.4.0)
|
|
93
92
|
activesupport (>= 6.1)
|
|
94
93
|
hashdiff (1.2.1)
|
|
95
|
-
i18n (1.
|
|
94
|
+
i18n (1.15.2)
|
|
96
95
|
concurrent-ruby (~> 1.0)
|
|
97
|
-
io-console (0.
|
|
96
|
+
io-console (0.9.2)
|
|
98
97
|
irb (1.18.0)
|
|
99
98
|
pp (>= 0.6.0)
|
|
100
99
|
prism (>= 1.3.0)
|
|
101
100
|
rdoc (>= 4.0.0)
|
|
102
101
|
reline (>= 0.4.2)
|
|
103
|
-
json (2.
|
|
104
|
-
language_server-protocol (3.17.0.
|
|
102
|
+
json (2.21.2)
|
|
103
|
+
language_server-protocol (3.17.0.6)
|
|
105
104
|
lint_roller (1.1.0)
|
|
106
105
|
logger (1.7.0)
|
|
107
|
-
loofah (2.25.
|
|
106
|
+
loofah (2.25.2)
|
|
108
107
|
crass (~> 1.0.2)
|
|
109
108
|
nokogiri (>= 1.12.0)
|
|
110
|
-
mail (2.9.
|
|
109
|
+
mail (2.9.1)
|
|
111
110
|
logger
|
|
112
111
|
mini_mime (>= 0.1.1)
|
|
113
112
|
net-imap
|
|
@@ -117,46 +116,43 @@ GEM
|
|
|
117
116
|
minitest (6.0.6)
|
|
118
117
|
drb (~> 2.0)
|
|
119
118
|
prism (~> 1.5)
|
|
120
|
-
net-imap (0.6.
|
|
119
|
+
net-imap (0.6.6)
|
|
121
120
|
date
|
|
122
121
|
net-protocol
|
|
123
122
|
net-pop (0.1.2)
|
|
124
123
|
net-protocol
|
|
125
|
-
net-protocol (0.
|
|
124
|
+
net-protocol (0.3.0)
|
|
126
125
|
timeout
|
|
127
126
|
net-smtp (0.5.1)
|
|
128
127
|
net-protocol
|
|
129
|
-
nokogiri (1.19.
|
|
128
|
+
nokogiri (1.19.4-aarch64-linux-gnu)
|
|
130
129
|
racc (~> 1.4)
|
|
131
|
-
nokogiri (1.19.
|
|
130
|
+
nokogiri (1.19.4-aarch64-linux-musl)
|
|
132
131
|
racc (~> 1.4)
|
|
133
|
-
nokogiri (1.19.
|
|
132
|
+
nokogiri (1.19.4-arm-linux-gnu)
|
|
134
133
|
racc (~> 1.4)
|
|
135
|
-
nokogiri (1.19.
|
|
134
|
+
nokogiri (1.19.4-arm-linux-musl)
|
|
136
135
|
racc (~> 1.4)
|
|
137
|
-
nokogiri (1.19.
|
|
136
|
+
nokogiri (1.19.4-arm64-darwin)
|
|
138
137
|
racc (~> 1.4)
|
|
139
|
-
nokogiri (1.19.
|
|
138
|
+
nokogiri (1.19.4-x86_64-darwin)
|
|
140
139
|
racc (~> 1.4)
|
|
141
|
-
nokogiri (1.19.
|
|
140
|
+
nokogiri (1.19.4-x86_64-linux-gnu)
|
|
142
141
|
racc (~> 1.4)
|
|
143
|
-
nokogiri (1.19.
|
|
142
|
+
nokogiri (1.19.4-x86_64-linux-musl)
|
|
144
143
|
racc (~> 1.4)
|
|
145
144
|
orm_adapter (0.5.0)
|
|
146
|
-
parallel (
|
|
147
|
-
parser (3.3.
|
|
145
|
+
parallel (2.2.0)
|
|
146
|
+
parser (3.3.12.0)
|
|
148
147
|
ast (~> 2.4.1)
|
|
149
148
|
racc
|
|
150
|
-
pp (0.6.
|
|
149
|
+
pp (0.6.4)
|
|
151
150
|
prettyprint
|
|
152
151
|
prettyprint (0.2.0)
|
|
153
152
|
prism (1.9.0)
|
|
154
|
-
psych (5.3.1)
|
|
155
|
-
date
|
|
156
|
-
stringio
|
|
157
153
|
public_suffix (7.0.5)
|
|
158
154
|
racc (1.8.1)
|
|
159
|
-
rack (3.2.
|
|
155
|
+
rack (3.2.7)
|
|
160
156
|
rack-session (2.1.2)
|
|
161
157
|
base64 (>= 0.1.0)
|
|
162
158
|
rack (>= 3.0.0)
|
|
@@ -168,12 +164,12 @@ GEM
|
|
|
168
164
|
activesupport (>= 5.0.0)
|
|
169
165
|
minitest
|
|
170
166
|
nokogiri (>= 1.6)
|
|
171
|
-
rails-html-sanitizer (1.7.
|
|
172
|
-
loofah (~> 2.25)
|
|
167
|
+
rails-html-sanitizer (1.7.1)
|
|
168
|
+
loofah (~> 2.25, >= 2.25.2)
|
|
173
169
|
nokogiri (>= 1.15.7, != 1.16.7, != 1.16.6, != 1.16.5, != 1.16.4, != 1.16.3, != 1.16.2, != 1.16.1, != 1.16.0.rc1, != 1.16.0)
|
|
174
|
-
railties (8.1.3)
|
|
175
|
-
actionpack (= 8.1.3)
|
|
176
|
-
activesupport (= 8.1.3)
|
|
170
|
+
railties (8.1.3.1)
|
|
171
|
+
actionpack (= 8.1.3.1)
|
|
172
|
+
activesupport (= 8.1.3.1)
|
|
177
173
|
irb (~> 1.13)
|
|
178
174
|
rackup (>= 1.0.0)
|
|
179
175
|
rake (>= 12.2)
|
|
@@ -182,14 +178,19 @@ GEM
|
|
|
182
178
|
zeitwerk (~> 2.6)
|
|
183
179
|
rainbow (3.1.1)
|
|
184
180
|
rake (13.4.2)
|
|
185
|
-
|
|
181
|
+
rbs (4.2.0)
|
|
182
|
+
logger
|
|
183
|
+
prism (>= 1.6.0)
|
|
184
|
+
tsort
|
|
185
|
+
rdoc (8.0.0)
|
|
186
186
|
erb
|
|
187
|
-
|
|
187
|
+
prism (>= 1.6.0)
|
|
188
|
+
rbs (>= 4.0.0)
|
|
188
189
|
tsort
|
|
189
190
|
regexp_parser (2.12.0)
|
|
190
|
-
reline (0.
|
|
191
|
+
reline (0.7.0)
|
|
191
192
|
io-console (~> 0.5)
|
|
192
|
-
responders (3.2.
|
|
193
|
+
responders (3.2.1)
|
|
193
194
|
actionpack (>= 7.0)
|
|
194
195
|
railties (>= 7.0)
|
|
195
196
|
rexml (3.4.4)
|
|
@@ -214,18 +215,18 @@ GEM
|
|
|
214
215
|
rspec-mocks (>= 3.13.0, < 5.0.0)
|
|
215
216
|
rspec-support (>= 3.13.0, < 5.0.0)
|
|
216
217
|
rspec-support (3.13.7)
|
|
217
|
-
rubocop (1.
|
|
218
|
+
rubocop (1.88.2)
|
|
218
219
|
json (~> 2.3)
|
|
219
220
|
language_server-protocol (~> 3.17.0.2)
|
|
220
221
|
lint_roller (~> 1.1.0)
|
|
221
|
-
parallel (
|
|
222
|
+
parallel (>= 1.10)
|
|
222
223
|
parser (>= 3.3.0.2)
|
|
223
224
|
rainbow (>= 2.2.2, < 4.0)
|
|
224
225
|
regexp_parser (>= 2.9.3, < 3.0)
|
|
225
226
|
rubocop-ast (>= 1.49.0, < 2.0)
|
|
226
227
|
ruby-progressbar (~> 1.7)
|
|
227
228
|
unicode-display_width (>= 2.4.0, < 4.0)
|
|
228
|
-
rubocop-ast (1.
|
|
229
|
+
rubocop-ast (1.50.0)
|
|
229
230
|
parser (>= 3.3.7.2)
|
|
230
231
|
prism (~> 1.7)
|
|
231
232
|
rubocop-performance (1.26.1)
|
|
@@ -234,24 +235,19 @@ GEM
|
|
|
234
235
|
rubocop-ast (>= 1.47.1, < 2.0)
|
|
235
236
|
ruby-progressbar (1.13.0)
|
|
236
237
|
securerandom (0.4.1)
|
|
237
|
-
simplecov (
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
sqlite3 (2.9.
|
|
244
|
-
sqlite3 (2.9.
|
|
245
|
-
sqlite3 (2.9.
|
|
246
|
-
|
|
247
|
-
sqlite3 (2.9.4-arm64-darwin)
|
|
248
|
-
sqlite3 (2.9.4-x86_64-darwin)
|
|
249
|
-
sqlite3 (2.9.4-x86_64-linux-gnu)
|
|
250
|
-
sqlite3 (2.9.4-x86_64-linux-musl)
|
|
251
|
-
standard (1.54.0)
|
|
238
|
+
simplecov (1.2.0)
|
|
239
|
+
sqlite3 (2.9.6-aarch64-linux-gnu)
|
|
240
|
+
sqlite3 (2.9.6-aarch64-linux-musl)
|
|
241
|
+
sqlite3 (2.9.6-arm-linux-gnu)
|
|
242
|
+
sqlite3 (2.9.6-arm-linux-musl)
|
|
243
|
+
sqlite3 (2.9.6-arm64-darwin)
|
|
244
|
+
sqlite3 (2.9.6-x86_64-darwin)
|
|
245
|
+
sqlite3 (2.9.6-x86_64-linux-gnu)
|
|
246
|
+
sqlite3 (2.9.6-x86_64-linux-musl)
|
|
247
|
+
standard (1.56.0)
|
|
252
248
|
language_server-protocol (~> 3.17.0.2)
|
|
253
249
|
lint_roller (~> 1.0)
|
|
254
|
-
rubocop (~> 1.
|
|
250
|
+
rubocop (~> 1.88.0)
|
|
255
251
|
standard-custom (~> 1.0.0)
|
|
256
252
|
standard-performance (~> 1.8)
|
|
257
253
|
standard-custom (1.0.2)
|
|
@@ -260,7 +256,6 @@ GEM
|
|
|
260
256
|
standard-performance (1.9.0)
|
|
261
257
|
lint_roller (~> 1.1)
|
|
262
258
|
rubocop-performance (~> 1.26.0)
|
|
263
|
-
stringio (3.2.0)
|
|
264
259
|
thor (1.5.0)
|
|
265
260
|
timeout (0.6.1)
|
|
266
261
|
tsort (0.2.0)
|
|
@@ -274,11 +269,11 @@ GEM
|
|
|
274
269
|
vcr (6.4.0)
|
|
275
270
|
warden (1.2.9)
|
|
276
271
|
rack (>= 2.0.9)
|
|
277
|
-
webmock (3.26.
|
|
272
|
+
webmock (3.26.4)
|
|
278
273
|
addressable (>= 2.8.0)
|
|
279
274
|
crack (>= 0.3.2)
|
|
280
275
|
hashdiff (>= 0.4.0, < 2.0.0)
|
|
281
|
-
zeitwerk (2.8.
|
|
276
|
+
zeitwerk (2.8.3)
|
|
282
277
|
|
|
283
278
|
PLATFORMS
|
|
284
279
|
aarch64-linux-gnu
|
data/README.md
CHANGED
|
@@ -20,12 +20,12 @@ Include `castle_devise` in your Gemfile:
|
|
|
20
20
|
gem 'castle_devise'
|
|
21
21
|
```
|
|
22
22
|
|
|
23
|
-
Create `config/initializers/castle_devise.rb` and fill in your API secret and
|
|
23
|
+
Create `config/initializers/castle_devise.rb` and fill in your API secret and publishable key from the [Castle Dashboard](https://dashboard.castle.io/settings/general)
|
|
24
24
|
|
|
25
25
|
```ruby
|
|
26
26
|
CastleDevise.configure do |config|
|
|
27
27
|
config.api_secret = ENV.fetch('CASTLE_API_SECRET')
|
|
28
|
-
config.
|
|
28
|
+
config.publishable_key = ENV.fetch('CASTLE_PK')
|
|
29
29
|
|
|
30
30
|
# When monitoring mode is enabled, CastleDevise sends
|
|
31
31
|
# requests to Castle but it doesn't act on the "deny" verdicts.
|
|
@@ -60,14 +60,20 @@ en:
|
|
|
60
60
|
|
|
61
61
|
(See [devise.en.yml in our specs](spec/dummy_app/config/locales/devise.en.yml#L40))
|
|
62
62
|
|
|
63
|
-
####
|
|
63
|
+
#### Browser SDK
|
|
64
64
|
|
|
65
|
-
|
|
65
|
+
Install [`@castleio/castle-js`](https://docs.castle.io/docs/sdk-browser) and serve the npm `dist` directory at `/vendor/castle-js` (keep `castle.umd.js` and the worker files together):
|
|
66
66
|
|
|
67
67
|
```ruby
|
|
68
68
|
<%= castle_javascript_tag %>
|
|
69
69
|
```
|
|
70
70
|
|
|
71
|
+
That loads `/vendor/castle-js/castle.umd.js` and seeds `window.Castle` before the script runs (3.x UMD is named `@castleio/castle-js`). Pass `src:` for a different UMD URL:
|
|
72
|
+
|
|
73
|
+
```ruby
|
|
74
|
+
<%= castle_javascript_tag(src: "/assets/castle.umd.js") %>
|
|
75
|
+
```
|
|
76
|
+
|
|
71
77
|
Add the following tag to the the `<form>` tag in both `devise/registrations/new.html.erb` and `devise/sessions/new.html.erb` (if you haven't generated them yet, run `rails generate devise:views`):
|
|
72
78
|
|
|
73
79
|
```ruby
|
|
@@ -76,26 +82,9 @@ Add the following tag to the the `<form>` tag in both `devise/registrations/new.
|
|
|
76
82
|
<% end %>
|
|
77
83
|
```
|
|
78
84
|
|
|
79
|
-
|
|
85
|
+
`castle_on_form_submit` uses 2.x `injectTokenOnSubmit` when present, and 2.x/3.x `createRequestToken` otherwise.
|
|
80
86
|
|
|
81
|
-
|
|
82
|
-
#### Further steps if you're using Webpacker
|
|
83
|
-
|
|
84
|
-
Add `@castleio/castle-js` to your package.json file:
|
|
85
|
-
|
|
86
|
-
```
|
|
87
|
-
yarn add @castleio/castle-js
|
|
88
|
-
```
|
|
89
|
-
|
|
90
|
-
configure castle in your application pack:
|
|
91
|
-
|
|
92
|
-
```javascript
|
|
93
|
-
import * as Castle from '@castleio/castle-js'
|
|
94
|
-
|
|
95
|
-
Castle.configure(YOUR_APPLICATION_ID);
|
|
96
|
-
```
|
|
97
|
-
|
|
98
|
-
for advanced configuration follow [the readme](https://www.npmjs.com/package/@castleio/castle-js#configuration)
|
|
87
|
+
You're set! Now verify that everything works by logging in to your application as any user. You should be able to see that User on the [Castle Users Page](https://dashboard.castle.io/users)
|
|
99
88
|
|
|
100
89
|
## How-Tos
|
|
101
90
|
|
|
@@ -213,6 +202,7 @@ end
|
|
|
213
202
|
### Setup
|
|
214
203
|
|
|
215
204
|
```bash
|
|
205
|
+
mise install
|
|
216
206
|
bundle install
|
|
217
207
|
```
|
|
218
208
|
|
|
@@ -221,9 +211,11 @@ bundle install
|
|
|
221
211
|
Most of the specs should pass just by running the following command:
|
|
222
212
|
|
|
223
213
|
```bash
|
|
224
|
-
|
|
214
|
+
mise run test
|
|
225
215
|
```
|
|
226
216
|
|
|
217
|
+
or `bundle exec rake`.
|
|
218
|
+
|
|
227
219
|
We also have a few VCR tests that will periodically rebuild the cassettes just to make sure that the integration with Castle API is working.
|
|
228
220
|
For those, you need to run your specs with a proper Castle API Secret:
|
|
229
221
|
|
|
@@ -12,9 +12,9 @@ module CastleDevise
|
|
|
12
12
|
# @return [String] Your API secret
|
|
13
13
|
attr_accessor :api_secret
|
|
14
14
|
|
|
15
|
-
# @!attribute
|
|
16
|
-
# @return [String]
|
|
17
|
-
attr_accessor :
|
|
15
|
+
# @!attribute publishable_key
|
|
16
|
+
# @return [String] Publishable key passed to @castleio/castle-js as { pk: }
|
|
17
|
+
attr_accessor :publishable_key
|
|
18
18
|
|
|
19
19
|
# @!attribute monitoring_mode
|
|
20
20
|
# When CastleDevise is in monitoring mode, it sends requests to Castle
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
(function () {
|
|
2
|
+
var CastleGlobal = window.Castle || window["@castleio/castle-js"];
|
|
3
|
+
var pk = __CASTLE_DEVISE_PK__;
|
|
4
|
+
if (!window.__castleDevise && CastleGlobal && typeof CastleGlobal.configure === "function") {
|
|
5
|
+
window.__castleDevise = CastleGlobal.configure({ pk: pk });
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
window.castleDeviseOnFormSubmit = function (event) {
|
|
9
|
+
var client = window.__castleDevise || window.Castle || window["@castleio/castle-js"];
|
|
10
|
+
// 2.x exposes injectTokenOnSubmit; 3.x only has createRequestToken on the configured instance.
|
|
11
|
+
if (client && typeof client.injectTokenOnSubmit === "function") {
|
|
12
|
+
return client.injectTokenOnSubmit(event);
|
|
13
|
+
}
|
|
14
|
+
if (!client || typeof client.createRequestToken !== "function") {
|
|
15
|
+
event.preventDefault();
|
|
16
|
+
return false;
|
|
17
|
+
}
|
|
18
|
+
var form = event.target;
|
|
19
|
+
if (form.getAttribute("data-castle-submitting") === "1") {
|
|
20
|
+
return true;
|
|
21
|
+
}
|
|
22
|
+
event.preventDefault();
|
|
23
|
+
client.createRequestToken().then(function (token) {
|
|
24
|
+
var field = form.querySelector('input[name="castle_request_token"]');
|
|
25
|
+
if (!field) {
|
|
26
|
+
field = document.createElement("input");
|
|
27
|
+
field.type = "hidden";
|
|
28
|
+
field.name = "castle_request_token";
|
|
29
|
+
form.appendChild(field);
|
|
30
|
+
}
|
|
31
|
+
field.value = token || "";
|
|
32
|
+
form.setAttribute("data-castle-submitting", "1");
|
|
33
|
+
if (typeof form.requestSubmit === "function") {
|
|
34
|
+
form.requestSubmit();
|
|
35
|
+
} else {
|
|
36
|
+
form.submit();
|
|
37
|
+
}
|
|
38
|
+
}).catch(function () {
|
|
39
|
+
form.setAttribute("data-castle-submitting", "1");
|
|
40
|
+
if (typeof form.requestSubmit === "function") {
|
|
41
|
+
form.requestSubmit();
|
|
42
|
+
} else {
|
|
43
|
+
form.submit();
|
|
44
|
+
}
|
|
45
|
+
});
|
|
46
|
+
return false;
|
|
47
|
+
};
|
|
48
|
+
})();
|
|
@@ -4,13 +4,23 @@ module CastleDevise
|
|
|
4
4
|
module Helpers
|
|
5
5
|
# Methods defined here will be available in all your views.
|
|
6
6
|
module CastleHelper
|
|
7
|
-
|
|
8
|
-
#
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
7
|
+
BOOTSTRAP_JS = File.read(File.expand_path("castle_devise.js", __dir__)).freeze
|
|
8
|
+
# 3.x UMD is named @castleio/castle-js, so seed module.exports as window.Castle before the script tag.
|
|
9
|
+
UMD_SHIM = <<~JS
|
|
10
|
+
if (!window.Castle) {
|
|
11
|
+
window.exports = window.exports || {};
|
|
12
|
+
window.module = window.module || { exports: window.exports };
|
|
13
|
+
window.Castle = window.module.exports;
|
|
14
|
+
}
|
|
15
|
+
JS
|
|
16
|
+
|
|
17
|
+
DEFAULT_UMD_SRC = "/vendor/castle-js/castle.umd.js"
|
|
18
|
+
|
|
19
|
+
# Loads castle.umd.js and configures it with { pk: }. Pass src: to use a
|
|
20
|
+
# different UMD URL, or src: nil when the host app already loaded the SDK.
|
|
12
21
|
#
|
|
13
|
-
#
|
|
22
|
+
# @param src [String, nil] URL or path of castle.umd.js (keep workers in the same directory)
|
|
23
|
+
# @return [String]
|
|
14
24
|
#
|
|
15
25
|
# @example
|
|
16
26
|
# # app/views/layouts/application.html.erb
|
|
@@ -21,14 +31,18 @@ module CastleDevise
|
|
|
21
31
|
# <title>Your app title</title>
|
|
22
32
|
#
|
|
23
33
|
# <!-- the rest of your layout -->
|
|
24
|
-
def castle_javascript_tag
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
34
|
+
def castle_javascript_tag(src: DEFAULT_UMD_SRC)
|
|
35
|
+
parts = []
|
|
36
|
+
if src
|
|
37
|
+
parts << javascript_tag(UMD_SHIM)
|
|
38
|
+
parts << javascript_include_tag(src)
|
|
39
|
+
end
|
|
40
|
+
parts << javascript_tag(castle_js_bootstrap)
|
|
41
|
+
safe_join(parts)
|
|
28
42
|
end
|
|
29
43
|
|
|
30
|
-
#
|
|
31
|
-
#
|
|
44
|
+
# onsubmit handler that mints castle_request_token via 2.x injectTokenOnSubmit
|
|
45
|
+
# or 2.x/3.x createRequestToken.
|
|
32
46
|
#
|
|
33
47
|
# @example
|
|
34
48
|
# <%= form_for(resource, as: resource_name, url: sessions_path(resource_name), html: { onsubmit: castle_on_form_submit }) do |f| %>
|
|
@@ -38,7 +52,13 @@ module CastleDevise
|
|
|
38
52
|
#
|
|
39
53
|
# @return [String]
|
|
40
54
|
def castle_on_form_submit
|
|
41
|
-
"
|
|
55
|
+
"castleDeviseOnFormSubmit(event)"
|
|
56
|
+
end
|
|
57
|
+
|
|
58
|
+
private
|
|
59
|
+
|
|
60
|
+
def castle_js_bootstrap
|
|
61
|
+
BOOTSTRAP_JS.sub("__CASTLE_DEVISE_PK__", CastleDevise.configuration.publishable_key.to_json)
|
|
42
62
|
end
|
|
43
63
|
end
|
|
44
64
|
end
|
data/mise.toml
ADDED
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: castle_devise
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.
|
|
4
|
+
version: 0.7.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Kacper Madej
|
|
@@ -80,6 +80,7 @@ files:
|
|
|
80
80
|
- ".octocov.yml"
|
|
81
81
|
- ".rspec"
|
|
82
82
|
- ".standard.yml"
|
|
83
|
+
- ".tool-versions"
|
|
83
84
|
- CHANGELOG.md
|
|
84
85
|
- Gemfile
|
|
85
86
|
- Gemfile.lock
|
|
@@ -100,6 +101,7 @@ files:
|
|
|
100
101
|
- lib/castle_devise/configuration.rb
|
|
101
102
|
- lib/castle_devise/context.rb
|
|
102
103
|
- lib/castle_devise/controllers/helpers.rb
|
|
104
|
+
- lib/castle_devise/helpers/castle_devise.js
|
|
103
105
|
- lib/castle_devise/helpers/castle_helper.rb
|
|
104
106
|
- lib/castle_devise/hooks/castle_protectable.rb
|
|
105
107
|
- lib/castle_devise/models/castle_protectable.rb
|
|
@@ -109,6 +111,7 @@ files:
|
|
|
109
111
|
- lib/castle_devise/rails.rb
|
|
110
112
|
- lib/castle_devise/sdk_facade.rb
|
|
111
113
|
- lib/castle_devise/version.rb
|
|
114
|
+
- mise.toml
|
|
112
115
|
homepage: https://github.com/castle/castle_devise
|
|
113
116
|
licenses:
|
|
114
117
|
- MIT
|
|
@@ -130,7 +133,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
130
133
|
- !ruby/object:Gem::Version
|
|
131
134
|
version: '0'
|
|
132
135
|
requirements: []
|
|
133
|
-
rubygems_version:
|
|
136
|
+
rubygems_version: 3.6.9
|
|
134
137
|
specification_version: 4
|
|
135
138
|
summary: Integrates Castle with Devise
|
|
136
139
|
test_files: []
|