Class: TokenProvider

Inherits:
Object
  • Object
show all
Includes:
DotNetServices::HTTPRequests, HTTPProxy
Defined in:
lib/acs/token_provider.rb

Class Method Summary collapse

Instance Method Summary collapse

Methods included from HTTPProxy

#set_http_web_proxy

Methods included from DotNetServices::HTTPRequests

#delete, #get, #post, #proxy, #put

Class Method Details

.compute_simple_web_token(issuer_name, issuer_secret) ⇒ Object

Computes the simple_web_token

  • issuer_name: Issuer name provided when the service is created

  • issuer_secret: Management key provided when the service is created



38
39
40
41
42
43
# File 'lib/acs/token_provider.rb', line 38

def self.compute_simple_web_token(issuer_name, issuer_secret)
  @token = TokenConstants.token_issuer + "=" + CGI::unescape(issuer_name)
   @hmcKey = self.token_hmc_key(CGI::unescape(@token), issuer_secret)
  @computedSimpleWebTokenString = @token + "&" + TokenConstants.token_digest256 + "=" + CGI::escape(@hmcKey)
  @computedSimpleWebTokenString
end

.token_hmc_key(token, issuer_secret_key) ⇒ Object

  • token: token_issuer + issuer_name

  • issuer_secret_key: Management key provided when the service is created



48
49
50
51
52
# File 'lib/acs/token_provider.rb', line 48

def self.token_hmc_key(token, issuer_secret_key)
   signature = Base64.encode64(HMAC::SHA256.digest(Base64.decode64(issuer_secret_key), token))
   signature = signature.gsub("\n", '')
   return signature
end

Instance Method Details

#issue_token(request_uri, params) ⇒ Object

Returns token received from the .NET services

  • request_uri: Request url

  • params: Parameter string to be sent as post request data



57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
# File 'lib/acs/token_provider.rb', line 57

def issue_token(request_uri, params)
  options = {}
  header = {
   'Content-Type' => TokenConstants.simple_auth_content_type,
   'Content-Length' => params.length.to_s,
   'Content-Language' => TokenConstants.content_language,
   'Accept' => '*/*'
 }
  options.store(:header, header)
  options.store(:use_ssl, true)
  response = post(request_uri, params, options)
  token_response = response.body
  token_response.extend ToHash
  the_token = token_response.to_hash['wrap_token']
  token_expires_in = token_response.to_hash['wrap_token_expires_in']
  TokenInfo.new(the_token, token_expires_in)
end