Class: AtomicLti::Params

Inherits:
Object
  • Object
show all
Defined in:
app/lib/atomic_lti/params.rb

Overview

This is for extracting data from the lti jwt in more human-readable ways

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(id_token_decoded) ⇒ Params

Returns a new instance of Params.



6
7
8
# File 'app/lib/atomic_lti/params.rb', line 6

def initialize(id_token_decoded)
  @token = id_token_decoded.with_indifferent_access
end

Instance Attribute Details

#tokenObject (readonly)

Returns the value of attribute token.



4
5
6
# File 'app/lib/atomic_lti/params.rb', line 4

def token
  @token
end

Instance Method Details

#ags_dataObject



87
88
89
# File 'app/lib/atomic_lti/params.rb', line 87

def ags_data
  token[AtomicLti::Definitions::AGS_CLAIM] || {}
end

#canvas_account_idObject



122
123
124
# File 'app/lib/atomic_lti/params.rb', line 122

def 
  custom_data[:canvas_account_id]
end

#canvas_assignment_idObject



130
131
132
# File 'app/lib/atomic_lti/params.rb', line 130

def canvas_assignment_id
  custom_data[:canvas_assignment_id]
end

#canvas_course_idObject



114
115
116
# File 'app/lib/atomic_lti/params.rb', line 114

def canvas_course_id
  custom_data[:canvas_course_id]
end

#canvas_course_nameObject



126
127
128
# File 'app/lib/atomic_lti/params.rb', line 126

def canvas_course_name
  custom_data[:canvas_course_name]
end

#canvas_section_idsObject



118
119
120
# File 'app/lib/atomic_lti/params.rb', line 118

def canvas_section_ids
  custom_data[:canvas_section_ids]
end

#client_idObject



26
27
28
# File 'app/lib/atomic_lti/params.rb', line 26

def client_id
  token[:aud]
end

#context_dataObject



30
31
32
# File 'app/lib/atomic_lti/params.rb', line 30

def context_data
  token[AtomicLti::Definitions::CONTEXT_CLAIM] || {}
end

#context_idObject



47
48
49
# File 'app/lib/atomic_lti/params.rb', line 47

def context_id
  context_data[:id]
end

#custom_dataObject

This extracts the custom parameters from the jwt token from the lti launch These values must be added to the developer key under “Custom Fields” for example: canvas_course_id=$Canvas.course.id



110
111
112
# File 'app/lib/atomic_lti/params.rb', line 110

def custom_data
  token[AtomicLti::Definitions::CUSTOM_CLAIM]&.reject { |_, s| s.to_s.start_with?("$Canvas") } || {}
end

#deep_linking_claimObject



95
96
97
# File 'app/lib/atomic_lti/params.rb', line 95

def deep_linking_claim
  token[AtomicLti::Definitions::DEEP_LINKING_CLAIM]
end

#deep_linking_dataObject



91
92
93
# File 'app/lib/atomic_lti/params.rb', line 91

def deep_linking_data
  token[AtomicLti::Definitions::DEEP_LINKING_DATA_CLAIM] || {}
end

#deployment_idObject



14
15
16
# File 'app/lib/atomic_lti/params.rb', line 14

def deployment_id
  token[AtomicLti::Definitions::DEPLOYMENT_ID]
end


103
104
105
# File 'app/lib/atomic_lti/params.rb', line 103

def is_deep_link
  AtomicLti::Definitions.deep_link_launch?(token)
end

#issObject



18
19
20
# File 'app/lib/atomic_lti/params.rb', line 18

def iss
  token[:iss]
end

#launch_contextObject



34
35
36
37
38
39
40
41
42
43
44
45
# File 'app/lib/atomic_lti/params.rb', line 34

def launch_context
  # This is an array, I'm not sure what it means to have more than one
  # value. In courses and accounts there's only one value
  contexts = context_data[:type] || []
  if contexts.include? AtomicLti::Definitions::COURSE_CONTEXT
    "COURSE"
  elsif contexts.include? AtomicLti::Definitions::ACCOUNT_CONTEXT
    "ACCOUNT"
  else
    "UNKNOWN"
  end
end

#launch_localeObject



83
84
85
# File 'app/lib/atomic_lti/params.rb', line 83

def launch_locale
  launch_presentation_data[:locale]
end

#launch_presentation_dataObject



79
80
81
# File 'app/lib/atomic_lti/params.rb', line 79

def launch_presentation_data
  token[AtomicLti::Definitions::LAUNCH_PRESENTATION] || {}
end

#lis_dataObject



59
60
61
# File 'app/lib/atomic_lti/params.rb', line 59

def lis_data
  token[AtomicLti::Definitions::LIS_CLAIM] || {}
end

#lti_advantage?Boolean

Returns:

  • (Boolean)


10
11
12
# File 'app/lib/atomic_lti/params.rb', line 10

def lti_advantage?
  true
end

#message_typeObject



99
100
101
# File 'app/lib/atomic_lti/params.rb', line 99

def message_type
  token[AtomicLti::Definitions::MESSAGE_TYPE]
end

#product_family_codeObject



67
68
69
# File 'app/lib/atomic_lti/params.rb', line 67

def product_family_code
  tool_platform_data[:product_family_code]
end


51
52
53
# File 'app/lib/atomic_lti/params.rb', line 51

def resource_link_data
  token[AtomicLti::Definitions::RESOURCE_LINK_CLAIM] || {}
end


55
56
57
# File 'app/lib/atomic_lti/params.rb', line 55

def resource_link_title
  resource_link_data[:title]
end

#tool_consumer_instance_guidObject



71
72
73
# File 'app/lib/atomic_lti/params.rb', line 71

def tool_consumer_instance_guid
  tool_platform_data[:guid]
end

#tool_consumer_instance_nameObject



75
76
77
# File 'app/lib/atomic_lti/params.rb', line 75

def tool_consumer_instance_name
  tool_platform_data[:name]
end

#tool_platform_dataObject



63
64
65
# File 'app/lib/atomic_lti/params.rb', line 63

def tool_platform_data
  token[AtomicLti::Definitions::TOOL_PLATFORM_CLAIM] || {}
end

#versionObject



22
23
24
# File 'app/lib/atomic_lti/params.rb', line 22

def version
  token[AtomicLti::Definitions::LTI_VERSION]
end