google_sign_in 0.1.1 → 0.1.2

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 78c821832dbcdff6dabee85bee7555ed38ea75f7
4
- data.tar.gz: 71d2aa594d621e5077d88b373f2dee0ec7289ac6
3
+ metadata.gz: 0b1d9fd3259a66f7304ba5130515d1cfda99211a
4
+ data.tar.gz: 3d0d4a66f812fe29aa70981e6331d9d1c0fbcebe
5
5
  SHA512:
6
- metadata.gz: 8886bd5132c3e69289b752a7f17bd361bd8a9e9db01e6a850d605d24b4c944d3b9d27ce3be477603435a3143bf828a10802e36b1ae0f1c3b1c47ba3b0fb07758
7
- data.tar.gz: 1ac5a753f98bb8788a391d963dac2a1e0922655bf595ec244b51319b5471e46cf7ec66725514b44a8f4c03ccfe1a914cb32a0e92e3dcb6c852839624a4545574
6
+ metadata.gz: 3911369b014ca6aeb902f89fd14406a99e053d2184560cd0392af98df174e1753e47bf01b73c92e34ffa22e443756d5e0479b295cedce8dbe41c4533658707d4
7
+ data.tar.gz: fca8d21ba6b78465353764be25ea8d2b5f2d8c4814813b785ec09684508be9ad11a5ac7149065d4d89da9fa693ad08b0e3cdc6d970ffa9acacde3d4dc5089bdc
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = 'google_sign_in'
3
- s.version = '0.1.1'
3
+ s.version = '0.1.2'
4
4
  s.authors = 'David Heinemeier Hansson'
5
5
  s.email = 'david@basecamp.com'
6
6
  s.summary = 'Sign in (or up) with Google for Rails applications'
@@ -7,14 +7,17 @@ module GoogleSignIn
7
7
  google_sign_in_javacript_include_tag +
8
8
  google_sign_in_client_id_meta_tag
9
9
 
10
- google_sign_in_javascript_tag +
10
+ google_sign_in_javascript_tag +
11
11
  google_sign_in_hidden_form_tag(url: url) +
12
12
  google_sign_in_click_handler(&block)
13
13
  end
14
14
 
15
15
  private
16
16
  def google_sign_in_javacript_include_tag
17
- javascript_include_tag "https://apis.google.com/js/platform.js?onload=setupGoogleSignIn", async: true, defer: true
17
+ javascript_include_tag "https://apis.google.com/js/api.js", async: true, defer: true,
18
+ onload: "this.onload=function(){};setupGoogleSignIn()",
19
+ onreadystatechange: "if (this.readyState === 'complete') this.onload()",
20
+ data: { turbolinks_track: :reload, force_turbolinks_reload: Time.now.to_i }
18
21
  end
19
22
 
20
23
  def google_sign_in_client_id_meta_tag
@@ -22,39 +25,46 @@ module GoogleSignIn
22
25
  end
23
26
 
24
27
  def google_sign_in_hidden_form_tag(url:)
25
- form_with url: url, id: "google_signin", html: { style: "display: none" } do |form|
26
- form.hidden_field :google_id_token, id: "google_id_token"
28
+ form_with url: url, html: { style: "display: none" } do |form|
29
+ form.hidden_field(:google_id_token, id: "google_sign_in_token") + form.submit(id: "google_sign_in_submit")
27
30
  end
28
31
  end
29
32
 
30
33
  def google_sign_in_click_handler(&block)
31
- tag.div(onclick: 'selectGoogleSignInAccount(event)') { capture(&block) }
34
+ tag.div(id: "google_sign_in_container", style: "visibility: hidden") { capture(&block) }
32
35
  end
33
36
 
34
37
  def google_sign_in_javascript_tag
35
- javascript_tag(<<-EOS
36
- function setupGoogleSignIn() {
37
- gapi.load("auth2", function () { gapi.auth2.init() })
38
- }
39
-
40
- function selectGoogleSignInAccount(event) {
41
- event.preventDefault()
42
-
43
- options = new gapi.auth2.SigninOptionsBuilder
44
- options.setPrompt("select_account")
45
-
46
- gapi.auth2.getAuthInstance().signIn(options).then(function (googleUser) {
47
- var token = googleUser.getAuthResponse().id_token
38
+ javascript_tag <<-JS.strip_heredoc
39
+ (function() {
40
+ function installAuthClient(callback) {
41
+ gapi.load("client:auth2", function() {
42
+ gapi.auth2.init().then(callback)
43
+ })
44
+ }
45
+
46
+ function installClickHandler() {
47
+ var element = document.getElementById("google_sign_in_container")
48
+ var options = new gapi.auth2.SigninOptionsBuilder()
49
+ options.setPrompt("select_account")
50
+ gapi.auth2.getAuthInstance().attachClickHandler(element, options, handleSignIn)
51
+ element.style.visibility = "visible"
52
+ }
48
53
 
49
- if (token !== null) {
50
- document.getElementById('google_id_token').value = token
51
- document.getElementById('google_signin').submit()
54
+ function handleSignIn(googleUser) {
55
+ var token = googleUser.getAuthResponse().id_token
56
+ if (token) {
57
+ document.getElementById("google_sign_in_token").value = token
58
+ document.getElementById("google_sign_in_submit").click()
52
59
  gapi.auth2.getAuthInstance().signOut()
53
60
  }
54
- })
55
- }
56
- EOS
57
- )
61
+ }
62
+
63
+ window.setupGoogleSignIn = function() {
64
+ installAuthClient(installClickHandler)
65
+ }
66
+ })()
67
+ JS
58
68
  end
59
69
  end
60
70
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: google_sign_in
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - David Heinemeier Hansson
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-07-30 00:00:00.000000000 Z
11
+ date: 2017-07-31 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport