Module: AtomicLti::DeepLinking

Defined in:
app/lib/atomic_lti/deep_linking.rb

Class Method Summary collapse

Class Method Details

########################################################### Create a jwt to sign a response to the platform



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'app/lib/atomic_lti/deep_linking.rb', line 7

def self.create_deep_link_jwt(iss:, deployment_id:, content_items:, deep_link_claim_data: nil)
  deployment = AtomicLti::Deployment.find_by(iss: iss, deployment_id: deployment_id)

  raise AtomicLti::Exceptions::NoLTIDeployment.new(iss: iss, deployment_id: deployment_id) if deployment.nil?

  install = deployment.install
  raise AtomicLti::Exceptions::NoLTIInstall.new(iss: iss, deployment_id: deployment_id) if install.nil?

  payload = {
    iss: install.client_id, # A unique identifier for the entity that issued the JWT
    aud: iss, # Authorization server identifier
    iat: Time.now.to_i, # Timestamp for when the JWT was created
    exp: Time.now.to_i + 300, # Timestamp for when the JWT should be treated as having expired
    # (after allowing a margin for clock skew)
    azp: install.client_id,
    nonce: SecureRandom.hex(10),
    AtomicLti::Definitions::MESSAGE_TYPE => "LtiDeepLinkingResponse",
    AtomicLti::Definitions::LTI_VERSION => "1.3.0",
    AtomicLti::Definitions::DEPLOYMENT_ID => deployment_id,
    AtomicLti::Definitions::CONTENT_ITEM_CLAIM => content_items,
  }

  if deep_link_claim_data.present?
    payload[AtomicLti::Definitions::DEEP_LINKING_DATA_CLAIM] = deep_link_claim_data
  end

  AtomicLti::Authorization.sign_tool_jwt(payload)
end