Class: RGigya::SigUtils
- Inherits:
-
Object
- Object
- RGigya::SigUtils
- Includes:
- RGigya
- Defined in:
- lib/rgigya/sig_utils.rb
Constant Summary
Constants included from RGigya
Class Method Summary collapse
-
.calculate_signature(base, key) ⇒ String
Value of the signature.
-
.current_time_in_milliseconds ⇒ String
Current time in milliseconds.
-
.get_dynamic_session_signature(glt_cookie, timeout_in_seconds) ⇒ String
generates the value for the session expiration cookie developers.gigya.com/010_Developer_Guide/87_Security#Defining_a_Session_Expiration_Cookie.
- .validate_friend_signature(uid, timestamp, friend_uid, signature) ⇒ Boolean
-
.validate_user_signature(uid, timestamp, signature) ⇒ Boolean
validates the signature from the api calls having to do with authentication developers.gigya.com/010_Developer_Guide/87_Security#Validate_the_UID_Signature_in_the_Social_Login_Process.
Methods included from RGigya
build_url, check_for_errors, config, log, method_missing, params_with_signature, parse_results, parse_results_secure, parse_results_with_signature, prepare_for_signature, required_parameters, respond_to?, verify_config_data
Class Method Details
.calculate_signature(base, key) ⇒ String
Returns value of the signature.
90 91 92 93 94 |
# File 'lib/rgigya/sig_utils.rb', line 90 def calculate_signature(base,key) base = base.encode('UTF-8') raw = OpenSSL::HMAC.digest('sha1',Base64.decode64(key), base) return Base64.encode64(raw).chomp.gsub(/\n/,'') end |
.current_time_in_milliseconds ⇒ String
Returns current time in milliseconds.
78 79 80 |
# File 'lib/rgigya/sig_utils.rb', line 78 def current_time_in_milliseconds() return DateTime.now.strftime("%Q") end |
.get_dynamic_session_signature(glt_cookie, timeout_in_seconds) ⇒ String
generates the value for the session expiration cookie developers.gigya.com/010_Developer_Guide/87_Security#Defining_a_Session_Expiration_Cookie
You want to use this if you want to terminate a session in the future
64 65 66 67 68 69 70 |
# File 'lib/rgigya/sig_utils.rb', line 64 def get_dynamic_session_signature(, timeout_in_seconds) expiration_time_unix_ms = (current_time_in_milliseconds().to_i/1000) + timeout_in_seconds expiration_time_unix = expiration_time_unix_ms.floor.to_s unsigned_expiration = "#{}_#{expiration_time_unix}" signed_expiration = calculate_signature(unsigned_expiration,@@api_secret) return "#{expiration_time_unix}_#{signed_expiration}" end |
.validate_friend_signature(uid, timestamp, friend_uid, signature) ⇒ Boolean
46 47 48 49 50 |
# File 'lib/rgigya/sig_utils.rb', line 46 def validate_friend_signature(uid, , friend_uid, signature) base = "#{}_#{friend_uid}_#{uid}" expected_signature = calculate_signature(base, @@api_secret) return expected_signature == signature end |
.validate_user_signature(uid, timestamp, signature) ⇒ Boolean
validates the signature from the api calls having to do with authentication developers.gigya.com/010_Developer_Guide/87_Security#Validate_the_UID_Signature_in_the_Social_Login_Process
27 28 29 30 31 |
# File 'lib/rgigya/sig_utils.rb', line 27 def validate_user_signature(uid, , signature) base = "#{}_#{uid}" expected_signature = calculate_signature(base, @@api_secret) return expected_signature == signature end |