Class: AtomicLti1v1::Lti1v1

Inherits:
Object
  • Object
show all
Defined in:
lib/atomic_lti_1v1/lti_1v1.rb

Class Method Summary collapse

Class Method Details

.is_lti_1v1?(request) ⇒ Boolean

Returns:

  • (Boolean)


3
4
5
6
7
# File 'lib/atomic_lti_1v1/lti_1v1.rb', line 3

def self.is_lti_1v1?(request)
  request.params['oauth_consumer_key'].present? &&
    request.params['oauth_signature'].present? &&
    request.params['lti_version'] == 'LTI-1p0'
end

.valid_lti_request?(request, lti_secret) ⇒ Boolean

Returns:

  • (Boolean)


14
15
16
17
18
19
20
21
# File 'lib/atomic_lti_1v1/lti_1v1.rb', line 14

def self.valid_lti_request?(request, lti_secret)
  authenticator = IMS::LTI::Services::MessageAuthenticator.new(request.url, request.params,
                                                               lti_secret)

  authenticator.valid_signature? &&
    AtomicLti1v1::Nonce.valid?(request.params['oauth_nonce']) &&
    valid_timestamp?(request)
end

.valid_timestamp?(request) ⇒ Boolean

Returns:

  • (Boolean)


9
10
11
12
# File 'lib/atomic_lti_1v1/lti_1v1.rb', line 9

def self.valid_timestamp?(request)
  # If timestamp is older than 5 minutes it's invalid
  !(DateTime.strptime(request.params['oauth_timestamp'], '%s') < 5.minutes.ago)
end