nm-gigya 0.0.6 → 0.0.7
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 +4 -4
- data/lib/gigya/connection.rb +41 -6
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ee733269f7033b90fddda7d89c2dd9ab5b92d352
|
4
|
+
data.tar.gz: 58e2ee6c9f6361329ea7c2831191f1621f817f9c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3fe661c2a0c74cfa8fe682105b586d30107bdce5d7c9a72d6f0e1fa23215e7c5c86090e5e219d19ff97e3baa50fbab379c53b51ebeb073dbac1d922debf8be17
|
7
|
+
data.tar.gz: 9270ca0fddb22b64f1d22b7961eb73e8cc070dc21ed7d73ef4f2d650c69ba7886102b53812c138194118b89c521bc85f85b5f98a7af40be1d87f1e272e4a03f3
|
data/lib/gigya/connection.rb
CHANGED
@@ -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 ||=
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
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]
|