Method: CF::UAA::TokenCoder#encode

Defined in:
lib/uaa/token_coder.rb

#encode(token_body = {}, algorithm = nil) ⇒ String

Encode a JWT token. Takes a hash of values to use as the token body. Returns a signed token in JWT format (header, body, signature).

Parameters:

  • algorithm (String) (defaults to: nil)

    – overrides default. See #initialize for possible values.

  • token_body (defaults to: {})

    Contents of the token in any object that can be converted to JSON.

Returns:

  • (String)

    a signed JWT token string in the form “xxxx.xxxxx.xxxx”.



166
167
168
169
170
# File 'lib/uaa/token_coder.rb', line 166

def encode(token_body = {}, algorithm = nil)
  token_body[:aud] = @options[:audience_ids] if @options[:audience_ids] && !token_body[:aud] && !token_body['aud']
  token_body[:exp] = Time.now.to_i + 7 * 24 * 60 * 60 unless token_body[:exp] || token_body['exp']
  self.class.encode(token_body, algorithm ? @options.merge(:algorithm => algorithm) : @options)
end