devise_capturable 0.0.7 → 0.0.8

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
  SHA1:
3
- metadata.gz: d35e33d8a0bbb3e0bc3f1c3c3673f399668b23ed
4
- data.tar.gz: 15d157ef99560f9e250099df336c08ebad8adb41
3
+ metadata.gz: e932376112dd1d89509666eb50bfd1392308756f
4
+ data.tar.gz: 3d4435c57dc7167d5e58abb7f680b6efed28d7f8
5
5
  SHA512:
6
- metadata.gz: 77e7dac34ed01b8310cf43a641a0556ba8495ad0a3640f0dd800781a0136f07565e25641da2f488eec912e8111c5890d54b6fad36795c59de61c4851820877e4
7
- data.tar.gz: 144cddbc639f09c62aada71287460ab9915b0f7a0fe95a717248e0b48debbe7ae8b7453987bd0e87695f00003be1c1141ccd5f2bcfbf3d920c6eabe1f1cfa58a
6
+ metadata.gz: 16747279659a61bc61e6c1fbb7ac2dad51a15d7486a242d42b997f22916b9a67f9aab536192b6ae975d89f8bfbc231fe4a445b3d600c6b7885cacf6ed0e24a7c
7
+ data.tar.gz: 4558d7617ff67409de2278a12e1dda0cf3d9486ed190b359037606090428b3f49502906d09f2220731768f32793164b7c345ff956a54bce1c1b68f8877005eb8
data/README.md CHANGED
@@ -40,6 +40,8 @@ Devise.setup do |config|
40
40
  config.capturable_server = "https://myapp.janraincapture.com"
41
41
  config.capturable_client_id = "myclientid"
42
42
  config.capturable_client_secret = "myclientsecret"
43
+ # Optional, see below to override config.capturable_redirect_uri
44
+ # config.capturable_redirect_uri = "http://sample.com"
43
45
  end
44
46
  ```
45
47
 
@@ -100,11 +102,9 @@ By default Devise will now create a database record when the user logs in for th
100
102
  The Janrain User Registration widget relies on settings that are 1) never used and 2) breaks the widget if they are not present. To circumvent this madness, this gem will automatically set a bunch of janrain setting variables for you:
101
103
 
102
104
  ```javascript
103
- // these settings will always be the same
105
+ // default settings for gem
104
106
  janrain.settings.capture.flowName = 'signIn';
105
107
  janrain.settings.capture.responseType = 'code';
106
-
107
- // these settings are never used but crashes the widget if not present
108
108
  janrain.settings.capture.redirectUri = 'http://stupidsettings.com';
109
109
  ```
110
110
 
@@ -112,7 +112,6 @@ You can delete these settings from your embed code, as the gem will set them for
112
112
 
113
113
  ## Changing defaults
114
114
 
115
-
116
115
  #### Overriding `before_capturable_create`
117
116
 
118
117
  There are times where you might want to save more than the `email` of your user in the Rails `User` model. You can override the `before_capturable_create` instance method to do this. Here's an example where I'm also saving the `uuid`. The `capture_data` parameter passed to the function is the Janrain Capture `entity` JSON result that has a bunch of information about the user, and the `params` parameter is the controller parameters.
@@ -161,6 +160,38 @@ Devise.setup do |config|
161
160
  end
162
161
  ```
163
162
 
163
+ #### Overriding `janrainCaptureWidgetOnLoad`
164
+
165
+ There are a number of reasons you may need to override the default `janrainCaptureWidgetOnLoad` Javascript function:
166
+
167
+ * To use the `signInEmbedded` flow instead of the default `signIn`
168
+ * To specify a `redirectUri` value (required to use Janrain's Federate feature)
169
+ * To add functionality to Janrain event handlers, or add more event handlers
170
+
171
+ To do so, you'll need to write your own `janrainCaptureWidgetOnLoad` function and include it separately. In this example, I'm replacing the default function with my own, included inline when loading the Janrain widget:
172
+
173
+ ```javascript
174
+ function janrainCaptureWidgetOnLoad() {
175
+ janrain.settings.capture.flowName = 'signInEmbedded';
176
+ janrain.settings.capture.responseType = 'code';
177
+ janrain.settings.capture.redirectUri = 'http://mydomain.com';
178
+ janrain.capture.ui.start();
179
+
180
+ // afterJanrainLogin is provided by Devise::Capturable to assist with
181
+ // server-side login
182
+ janrain.events.onCaptureLoginSuccess.addHandler(afterJanrainLogin);
183
+ janrain.events.onCaptureRegistrationSuccess.addHandler(afterJanrainLogin);
184
+ };
185
+ ```
186
+
187
+ Finally, I can also provide an optional path to send the Janrain `authorizationCode` to in my application, if using a Devise resource not named `User`:
188
+
189
+ ```erb
190
+ janrain.events.onCaptureRegistrationSuccess.addHandler(function(result) {
191
+ afterJanrainLogin(result, '<%= new_admin_session_path %>');
192
+ });
193
+ ```
194
+
164
195
  ## Running the Tests
165
196
 
166
197
  Run the tests with the `rspec` command.
@@ -19,7 +19,7 @@ Gem::Specification.new do |gem|
19
19
 
20
20
  gem.add_runtime_dependency("httparty")
21
21
  gem.add_development_dependency("devise")
22
- gem.add_development_dependency("rspec")
22
+ gem.add_development_dependency("rspec", "~> 2.14")
23
23
  gem.add_development_dependency("rails")
24
24
 
25
25
  end
@@ -1,7 +1,9 @@
1
- function afterJanrainLogin(result)
1
+ function afterJanrainLogin(result, path)
2
2
  {
3
+ path = path || "/users/sign_in";
4
+
3
5
  // create form
4
- var form = $('<form accept-charset="UTF-8" action="/users/sign_in" method="post" id="capturable-inject-form"></form>')
6
+ var form = $('<form accept-charset="UTF-8" action="' + path + '" method="post" id="capturable-inject-form"></form>')
5
7
 
6
8
  // create hidden div in form
7
9
  var hidden_els = $('<div style="margin:0;padding:0;display:inline"></div>')
@@ -10,9 +10,11 @@ module Devise
10
10
  #debug_output $stderr
11
11
 
12
12
  def self.token(code)
13
+ redirect_uri = Devise.capturable_redirect_uri || 'http://stupidsettings.com'
14
+
13
15
  post("#{Devise.capturable_server}/oauth/token", :query => {
14
16
  code: code,
15
- redirect_uri: "http://stupidsettings.com",
17
+ redirect_uri: redirect_uri,
16
18
  grant_type: 'authorization_code',
17
19
  client_id: Devise.capturable_client_id,
18
20
  client_secret: Devise.capturable_client_secret,
@@ -33,7 +33,7 @@ module Devise
33
33
 
34
34
  success!(user)
35
35
  rescue Exception => e
36
- fail!(:capturable_invalid)
36
+ fail!("Login failed: #{e}")
37
37
  end
38
38
  end
39
39
 
@@ -1,5 +1,5 @@
1
1
  module Devise
2
2
  module Capturable
3
- VERSION = "0.0.7"
3
+ VERSION = "0.0.8"
4
4
  end
5
5
  end
@@ -11,6 +11,7 @@ module Devise
11
11
  mattr_accessor :capturable_server
12
12
  mattr_accessor :capturable_client_id
13
13
  mattr_accessor :capturable_client_secret
14
+ mattr_accessor :capturable_redirect_uri
14
15
  end
15
16
 
16
17
  I18n.load_path.unshift File.join(File.dirname(__FILE__), *%w[devise_capturable locales en.yml])
data/spec/api_spec.rb CHANGED
@@ -7,12 +7,13 @@ describe 'Devise::Capturable::API' do
7
7
  Devise.stub(:capturable_server).and_return("https://something.dev.janraincapture.com")
8
8
  Devise.stub(:capturable_client_id).and_return("thisis")
9
9
  Devise.stub(:capturable_client_secret).and_return("atest")
10
+ Devise.stub(:capturable_redirect_uri).and_return("http://sample.com")
10
11
  end
11
12
 
12
13
  it "should get token from code" do
13
14
  Devise::Capturable::API.should_receive(:post).with("https://something.dev.janraincapture.com/oauth/token", :query => {
14
15
  code: "abcdef",
15
- redirect_uri: "http://stupidsettings.com",
16
+ redirect_uri: "http://sample.com",
16
17
  grant_type: 'authorization_code',
17
18
  client_id: "thisis",
18
19
  client_secret: "atest",
@@ -9,7 +9,7 @@ describe 'View Helpers' do
9
9
  end
10
10
  test = Testing.new
11
11
  link = test.link_to_capturable("Login")
12
- link.should == '<a class="capture_modal_open" href="#" id="capture_signin_link">Login</a>'
12
+ link.should == '<a href="#" class="capture_modal_open" id="capture_signin_link">Login</a>'
13
13
  end
14
14
 
15
15
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: devise_capturable
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.7
4
+ version: 0.0.8
5
5
  platform: ruby
6
6
  authors:
7
7
  - Rune Skjoldborg Madsen
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-12-11 00:00:00.000000000 Z
11
+ date: 2014-02-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: httparty
@@ -42,16 +42,16 @@ dependencies:
42
42
  name: rspec
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
- - - '>='
45
+ - - ~>
46
46
  - !ruby/object:Gem::Version
47
- version: '0'
47
+ version: '2.14'
48
48
  type: :development
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
- - - '>='
52
+ - - ~>
53
53
  - !ruby/object:Gem::Version
54
- version: '0'
54
+ version: '2.14'
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: rails
57
57
  requirement: !ruby/object:Gem::Requirement