Class: D2L::Valence::AuthTokens

Inherits:
Object
  • Object
show all
Defined in:
lib/d2l/valence/auth_tokens.rb

Overview

AuthTokens

Class to generate authentication tokens for D2L Valance API calls

Constant Summary collapse

APP_ID_PARAM =
'x_a'.freeze
USER_ID_PARAM =
'x_b'.freeze
SIGNATURE_BY_APP_KEY_PARAM =
'x_c'.freeze
SIGNATURE_BY_USER_KEY_PARAM =
'x_d'.freeze
TIMESTAMP_PARAM =
'x_t'.freeze

Instance Method Summary collapse

Constructor Details

#initialize(request:) ⇒ AuthTokens

Returns a new instance of AuthTokens.

Parameters:



13
14
15
16
17
# File 'lib/d2l/valence/auth_tokens.rb', line 13

def initialize(request:)
  @call = request
  @user_context = @call.user_context
  @app_context = @user_context.app_context
end

Instance Method Details

#adjusted_timestampInteger

Generates a timestamp with time skew between server and client taken into consideration

Returns:

  • (Integer)

    Server skew adjusted timestamp in seconds



32
33
34
# File 'lib/d2l/valence/auth_tokens.rb', line 32

def adjusted_timestamp
  @adjusted_timestamp ||= Time.now.to_f.to_i + @user_context.server_skew
end

#generateHash

Generates the auth tokens as a Hash for inclusion in the final URI query string

Returns:

  • (Hash)

    tokens for authenticated call



21
22
23
24
25
26
27
# File 'lib/d2l/valence/auth_tokens.rb', line 21

def generate
  @tokens = {}
  add_app_tokens
  add_user_tokens
  add_timestamp_token
  @tokens
end