nm-gigya 0.0.8 → 0.0.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
  SHA1:
3
- metadata.gz: 36ffb4371201559fcd8fc689e8feb290f0458494
4
- data.tar.gz: fed0e847361067612d7564d280fe9b37bae47cb5
3
+ metadata.gz: 529877882c8e1a5a32d0323173f2a78415728337
4
+ data.tar.gz: c197dacbb05f7bdef51de6838d71e944aaa112e9
5
5
  SHA512:
6
- metadata.gz: d56dda8e552af33e70fef3de63a6d7dcc3a6fdb7a115d312f39c10e3d0805e3d8977ccb2ff8e4b41df3520e09a590ca07a702175c68474057c481cf62e6aa9cc
7
- data.tar.gz: f2a2fe2772f41e072dc33fe7242861a76343fbd530557b6bc1137480c5b3f4149aeccb28dfe1e6f41b92569238237657bd9543f995032af340a9928a40111398
6
+ metadata.gz: da142cccb79cbf7cbc8b30a9835867bb6c82baa013927366ee5d5b1352c35e76a5387164852e0fb99d8c3c74e06922f7b8e8f144d9b67e83cab67c4b3d483631
7
+ data.tar.gz: 837cbed57220f5e4033d8f08c950b95048310e6c4f8af6628574f8cd01bef477e6fd27828d8c0a2761f938dba987f2b9f413545943d38171e394dc50ffb7b97e
@@ -270,6 +270,10 @@ module Gigya
270
270
  return user_jwt_info
271
271
  end
272
272
 
273
+ def api_key
274
+ @opts[:api_key]
275
+ end
276
+
273
277
  def login(username, password)
274
278
  user_info = api_get("accounts", "login", {:loginID => username, :password => password, :targetEnv => "mobile"}, :throw_on_error => true)
275
279
  uid = user_info["UID"]
@@ -0,0 +1,120 @@
1
+ # This module is a mix-in that makes for much easier Gigya UI integration in Gigya apps.
2
+ # Essentially if you include this, it is very straightforward to do a Gigya login mechanism.
3
+ module Gigya::Session
4
+ def self.included(base)
5
+ base.include Gigya::ControllerUtils
6
+ base.extend ClassMethods
7
+ end
8
+
9
+ def destroy
10
+ cookies.delete Gigya::ControllerUtils::GIGYA_COOKIE_PARAM
11
+ end
12
+
13
+ def create
14
+ gigya_save_jwt(self.class.gigya_token_storage || :cookie)
15
+
16
+ if params[:redirect].blank?
17
+ redir = self.class.gigya_after_login_redirect
18
+ case redir
19
+ when String
20
+ redirect_to redir
21
+ when Symbol
22
+ redirect_to self.send(redir)
23
+ else
24
+ redirect_to redir.call
25
+ end
26
+ else
27
+ redirect_to params[:redirect]
28
+ end
29
+ end
30
+
31
+ def new
32
+ head_code = <<EOF
33
+ <script type='text/javascript' src='https://cdns.gigya.com/js/gigya.js?apikey=#{self.class.gigya_api_key}'></script>
34
+ <script type="text/javascript">
35
+ function did_login(evt, resp) {
36
+ form = document.getElementById("hidden-login-form");
37
+ gtok = document.getElementById("gigya-token");
38
+
39
+ gtok.value = resp.id_token;
40
+ form.submit();
41
+ }
42
+
43
+ var expire_time = #{self.class.gigya_token_expire_time};
44
+ gigya.accounts.showScreenSet({
45
+ screenSet: '#{self.class.gigya_screen_set}',
46
+ startScreen: '#{self.class.gigya_start_screen}',
47
+ containerID: 'gigya-screenset-container',
48
+ deviceType: 'mobile',
49
+ sessionExpiration: expire_time,
50
+ onAfterSubmit: function(evt) {
51
+ if(evt.form == 'gigya-login-form' && evt.response.errorCode == 0) {
52
+ gigya.accounts.getJWT({
53
+ fields: "#{self.class.gigya_jwt_fields}",
54
+ expiration: expire_time,
55
+ callback: function(resp) {
56
+ did_login(evt, resp);
57
+ }
58
+ });
59
+ }
60
+ }
61
+ });
62
+ </script>
63
+ EOF
64
+ body_code = <<EOF
65
+ <%= form_tag request.path.gsub('/new', ''), :id => "hidden-login-form" do %>
66
+ <%= hidden_field_tag :redirect, params[:redirect] %>
67
+ <%= hidden_field_tag :gigya_token, "", :id => "gigya-token" %>
68
+ <% end %>
69
+ <div class="gigya-screenset-class" id="gigya-screenset-container"></div>
70
+ EOF
71
+
72
+ if self.class.gigya_script_content_for.present?
73
+ head_code = "<% content_for :#{gigya_script_content_for} do %>#{head_code}<% end %>"
74
+ end
75
+
76
+ full_erb = head_code + body_code
77
+ render :inline => full_erb
78
+ end
79
+
80
+ module ClassMethods
81
+ def gigya_screen_set(val = nil)
82
+ return (@gigya_screen_set || "Default-RegistrationLogin") if val.nil?
83
+ @gigya_screen_set = val
84
+ end
85
+
86
+ def gigya_start_screen(val = nil)
87
+ return (@gigya_start_screen || "gigya-login-screen") if val.nil?
88
+ @gigya_start_screen = val
89
+ end
90
+
91
+ def gigya_token_storage(val = nil)
92
+ return (@gigya_token_storage || :cookie) if val.nil?
93
+ @gigya_token_storage = val
94
+ end
95
+
96
+ def gigya_after_login_redirect(val = nil)
97
+ return (@gigya_after_login_redirect || :root_path) if val.nil?
98
+ @gigya_after_login_redirect = val
99
+ end
100
+
101
+ def gigya_script_content_for(val = nil)
102
+ return @gigya_script_content_for if val.nil?
103
+ @gigya_script_content_for = val
104
+ end
105
+
106
+ def gigya_token_expire_time(val = nil)
107
+ return (@gigya_token_expire_time || (60 * 60 * 24)) if val.nil?
108
+ end
109
+
110
+ def gigya_jwt_fields(val = nil)
111
+ return (@gigya_jwt_fields || "firstName,lastName,email") if val.nil?
112
+ @gigya_jwt_fields = val
113
+ end
114
+
115
+ def gigya_api_key(val = nil)
116
+ return (@gigya_api_key || Gigya::Connection.shared_connection.api_key) if val.nil?
117
+ @gigya_api_key = val
118
+ end
119
+ end
120
+ end
data/lib/gigya.rb CHANGED
@@ -2,3 +2,4 @@ require 'httparty'
2
2
 
3
3
  require "gigya/connection"
4
4
  require "gigya/controller_utils" if defined?(Rails)
5
+ require "gigya/session"
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: nm-gigya
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.8
4
+ version: 0.0.13
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jonathan Bartlett
@@ -48,6 +48,7 @@ files:
48
48
  - lib/gigya.rb
49
49
  - lib/gigya/connection.rb
50
50
  - lib/gigya/controller_utils.rb
51
+ - lib/gigya/session.rb
51
52
  homepage: http://www.newmedio.com/
52
53
  licenses:
53
54
  - MIT