You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Load @castleio/castle-js UMD from npm and support 2.x and 3.x (#85)
* Load @castleio/castle-js from /vendor/castle-js and support 2.x and 3.x.
* Load castle.umd.js and seed window.Castle for the 3.x UMD global.
* Drop app_id. Configure with api_secret and publishable_key only.
* Document public/vendor copy for castle-js UMD and add local mise pins.
* Let castle_javascript_tag take a hosted UMD src instead of serving node_modules.
* Load castle.umd.js by default from /vendor/castle-js.
Copy file name to clipboardExpand all lines: README.md
+16-24Lines changed: 16 additions & 24 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -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 APP_ID from the [Castle Dashboard](https://dashboard.castle.io/settings/general)
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.app_id=ENV.fetch('CASTLE_APP_ID')
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
-
#### Further steps if you're not using Webpacker
63
+
#### Browser SDK
64
64
65
-
Include Castle's c.js script in the head section of your layout:
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:
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
-
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)
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*asCastlefrom'@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
-
bundle exec rake
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:
0 commit comments