nm-gigya 0.0.6 → 0.0.7

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. checksums.yaml +4 -4
  2. data/lib/gigya/connection.rb +41 -6
  3. metadata +1 -1
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: c2600b2a029001bec188706347f7c8040b08fc2a
4
- data.tar.gz: ac59bf9c2b25c1864a24c6e247eb574552894a75
3
+ metadata.gz: ee733269f7033b90fddda7d89c2dd9ab5b92d352
4
+ data.tar.gz: 58e2ee6c9f6361329ea7c2831191f1621f817f9c
5
5
  SHA512:
6
- metadata.gz: 9a63c574d1ef8960248a6b6f70c61f9f823f511e48d74aaa72971eeae497332c92e6e3fd5cc9a9ca32076cb14b9a42ac05822969976066b44126ae2f39ffe36a
7
- data.tar.gz: 97de7e9ba5310350fed94c43151e7e9e869627d71df1642c75280fd055f1758ba167f747a8b794e4e8a2ac2344b348ad5dc0329fb9cc604e2a46493da2c3790b
6
+ metadata.gz: 3fe661c2a0c74cfa8fe682105b586d30107bdce5d7c9a72d6f0e1fa23215e7c5c86090e5e219d19ff97e3baa50fbab379c53b51ebeb073dbac1d922debf8be17
7
+ data.tar.gz: 9270ca0fddb22b64f1d22b7961eb73e8cc070dc21ed7d73ef4f2d650c69ba7886102b53812c138194118b89c521bc85f85b5f98a7af40be1d87f1e272e4a03f3
@@ -2,6 +2,7 @@ require "openssl"
2
2
  require "httparty"
3
3
  require "jwt"
4
4
  require "json"
5
+ require "securerandom"
5
6
 
6
7
  # Required for the dynamic modules
7
8
  #require "active_support"
@@ -151,14 +152,22 @@ module Gigya
151
152
  end
152
153
 
153
154
  class Connection
155
+ attr_accessor :jwt_skip_validation
156
+
154
157
  GIGYA_BASE_URL="gigya.com"
155
158
  def self.shared_connection
156
- @@connection ||= self.new(
157
- :datacenter => ENV["GIGYA_DATACENTER"] || "us1",
158
- :api_key => ENV["GIGYA_API_KEY"],
159
- :user_key => ENV["GIGYA_USER_KEY"],
160
- :user_secret => ENV["GIGYA_USER_SECRET"]
161
- )
159
+ @@connection ||= begin
160
+ conn = self.new(
161
+ :datacenter => ENV["GIGYA_DATACENTER"] || "us1",
162
+ :api_key => ENV["GIGYA_API_KEY"],
163
+ :user_key => ENV["GIGYA_USER_KEY"],
164
+ :user_secret => ENV["GIGYA_USER_SECRET"]
165
+ )
166
+ conn.jwt_skip_validation = false
167
+ conn
168
+ end
169
+
170
+ return @@connection
162
171
  end
163
172
 
164
173
  def self.shared_connection=(conn)
@@ -177,6 +186,10 @@ module Gigya
177
186
  x.gsub("-", "+").gsub("_", "/")
178
187
  end
179
188
 
189
+ def self.strange_unmunge(x)
190
+ x.gsub("+", "-").gsub("/", "_")
191
+ end
192
+
180
193
  # According to https://developers.gigya.com/display/GD/How+To+Validate+A+Gigya+id_token
181
194
  # Gigya JWTs are not in the standard format, but must be munged first
182
195
  def self.reformat_jwt(jwt_token)
@@ -200,6 +213,25 @@ module Gigya
200
213
  @cached_data = {}
201
214
  end
202
215
 
216
+ def build_test_jwt(uid = nil, data_options = {}, expiration = nil, gigya_munge = true)
217
+ data_options = (data_options || {}).dup
218
+ data_options["sub"] = uid unless uid.nil?
219
+ data_options["sub"] ||=SecureRandom.uuid
220
+ data_options["apiKey"] ||= (@opts[:api_key] || "no_api_key")
221
+ data_options["iss"] ||= "https://fidm.gigya.com/jwt/#{data_options["apiKey"]}/"
222
+ data_options["iat"] ||= rand(10000000000)
223
+ data_options["exp"] = (Time.now + expiration).to_i unless expiration.nil?
224
+ data_options["exp"] ||= (Time.now + (60 * 60)).to_i
225
+ data_options["firstName"] ||= "Jim#{rand(10000000)}"
226
+ data_options["lastName"] ||= "Jimmersly#{rand(10000000)}"
227
+ data_options["email"] ||= "jim+#{rand(10000000)}@example.com"
228
+
229
+ jwt_str = JWT.encode(data_options, nil, 'none', {:typ => "JWT"})
230
+ jwt_str = self.class.strange_unmunge(jwt_str) if gigya_munge
231
+
232
+ return jwt_str
233
+ end
234
+
203
235
  def connection_options
204
236
  @opts
205
237
  end
@@ -221,6 +253,9 @@ module Gigya
221
253
  jwt_token = self.class.reformat_jwt(jwt_token) if gigya_munge
222
254
 
223
255
  user_jwt_info, signing_jwt_info = JWT.decode(jwt_token, nil, false)
256
+
257
+ return user_jwt_info if jwt_skip_validation
258
+
224
259
  signing_key_id = signing_jwt_info["keyid"]
225
260
  @cached_data["jwt_public_keys"] ||= {}
226
261
  k = @cached_data["jwt_public_keys"][signing_key_id]
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.6
4
+ version: 0.0.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jonathan Bartlett