Class: Woople::Tokenizer

Inherits:
Object
  • Object
show all
Defined in:
lib/woople/tokenizer.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(importer_key, api_key, data = {}) ⇒ Tokenizer

Returns a new instance of Tokenizer.



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/woople/tokenizer.rb', line 10

def initialize( importer_key, api_key, data = {} )
  # create the signed key
  signed_key = EzCrypto::Key.with_password( importer_key, api_key )

  # create the data-object, using the required fields
  defaults = {
    :expires => 10.minutes.from_now.to_s # expires 10 minutes from now
  }

  data = defaults.merge(data)

  # encode the data-object to JSON, and encrypt
  encrypted_data = signed_key.encrypt( data.to_json )

  # generate the SSO-Token
  @sso_token = CGI.escape( Base64.encode64( encrypted_data ).gsub(/\n/, "") )
end

Class Method Details

.decrypt(importer_key, api_key, encrypted_token) ⇒ Object



32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/woople/tokenizer.rb', line 32

def self.decrypt( importer_key, api_key, encrypted_token )
  # encrypted token must have been run through CGI.unescape() before coming into this method

  # create the signed key
  signed_key = EzCrypto::Key.with_password( importer_key, api_key )

  # decode the data-object
  decoded = signed_key.decrypt( Base64.decode64( encrypted_token ) )

  # convert the object to a hash
  HashWithIndifferentAccess.new( ActiveSupport::JSON.decode(decoded) )
end

Instance Method Details

#sso_tokenObject



28
29
30
# File 'lib/woople/tokenizer.rb', line 28

def sso_token
  @sso_token
end