qalam_oauth_engine 3.0.0 → 3.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/MIT-LICENSE +0 -0
- data/README.md +0 -0
- data/Rakefile +0 -0
- data/app/controllers/canvas_oauth/canvas_controller.rb +1 -1
- data/app/controllers/canvas_oauth/oauth_application_controller.rb +0 -0
- data/app/models/canvas_oauth/authorization.rb +0 -0
- data/config/canvas.yml.example +0 -0
- data/config/routes.rb +0 -0
- data/db/migrate/20121121005358_create_canvas_oauth_authorizations.rb +0 -0
- data/lib/canvas_oauth.rb +0 -0
- data/lib/canvas_oauth/canvas_api.rb +131 -95
- data/lib/canvas_oauth/canvas_api_extensions.rb +0 -0
- data/lib/canvas_oauth/canvas_application.rb +0 -0
- data/lib/canvas_oauth/canvas_config.rb +3 -3
- data/lib/canvas_oauth/config.rb +0 -0
- data/lib/canvas_oauth/default_utf8_parser.rb +0 -0
- data/lib/canvas_oauth/engine.rb +0 -0
- data/lib/canvas_oauth/version.rb +1 -1
- data/lib/tasks/canvas_oauth_tasks.rake +0 -0
- data/spec/controllers/canvas_oauth/canvas_controller_spec.rb +0 -0
- data/spec/dummy/README.rdoc +0 -0
- data/spec/dummy/Rakefile +0 -0
- data/spec/dummy/app/controllers/application_controller.rb +0 -0
- data/spec/dummy/app/controllers/welcome_controller.rb +0 -0
- data/spec/dummy/config.ru +0 -0
- data/spec/dummy/config/application.rb +0 -0
- data/spec/dummy/config/boot.rb +0 -0
- data/spec/dummy/config/canvas.yml +0 -0
- data/spec/dummy/config/database.yml +0 -0
- data/spec/dummy/config/environment.rb +0 -0
- data/spec/dummy/config/environments/development.rb +0 -0
- data/spec/dummy/config/environments/production.rb +0 -0
- data/spec/dummy/config/environments/test.rb +0 -0
- data/spec/dummy/config/initializers/backtrace_silencers.rb +0 -0
- data/spec/dummy/config/initializers/inflections.rb +0 -0
- data/spec/dummy/config/initializers/mime_types.rb +0 -0
- data/spec/dummy/config/initializers/secret_token.rb +0 -0
- data/spec/dummy/config/initializers/session_store.rb +0 -0
- data/spec/dummy/config/initializers/wrap_parameters.rb +0 -0
- data/spec/dummy/config/locales/en.yml +0 -0
- data/spec/dummy/config/routes.rb +0 -0
- data/spec/dummy/db/development.sqlite3 +0 -0
- data/spec/dummy/db/migrate/20160711200737_create_canvas_oauth_authorizations.canvas_oauth.rb +0 -0
- data/spec/dummy/db/schema.rb +0 -0
- data/spec/dummy/db/test.sqlite3 +0 -0
- data/spec/dummy/log/development.log +0 -0
- data/spec/dummy/log/test.log +0 -0
- data/spec/dummy/public/404.html +0 -0
- data/spec/dummy/public/422.html +0 -0
- data/spec/dummy/public/500.html +0 -0
- data/spec/dummy/public/favicon.ico +0 -0
- data/spec/dummy/public/robots.txt +0 -0
- data/spec/lib/canvas_oauth/canvas_api_extensions_spec.rb +0 -0
- data/spec/lib/canvas_oauth/canvas_api_spec.rb +0 -0
- data/spec/lib/canvas_oauth/default_utf8_parser_spec.rb +0 -0
- data/spec/models/canvas_oauth/authorization_spec.rb +0 -0
- data/spec/spec_helper.rb +0 -0
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5a211fbb4dc88d7fdd02b18476934e0aaeb9b8b1fb51264b907a82fbeb594a6f
|
4
|
+
data.tar.gz: a94cb0321d02c42d7aa2cd08b37d138512e71ec6200322f96a97a101e964e1b5
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 307140f17ec1b239e871bd6cf198c074f19511cfec07117221a992a4ee0944a0e7296787ecd7a6562ce6ef15ced7d0ba8ac6d6584b42f9f7990062270a4834ae
|
7
|
+
data.tar.gz: 959873829e421e85ba8a53aba9e19d7a30f51742d83d49c6c5d950fadcfdab4c68f4612e3c996e5576cc5959fe41d691a8dc90584a92fa88adae9458ba05f6ea
|
data/MIT-LICENSE
CHANGED
File without changes
|
data/README.md
CHANGED
File without changes
|
data/Rakefile
CHANGED
File without changes
|
File without changes
|
File without changes
|
data/config/canvas.yml.example
CHANGED
File without changes
|
data/config/routes.rb
CHANGED
File without changes
|
File without changes
|
data/lib/canvas_oauth.rb
CHANGED
File without changes
|
@@ -8,7 +8,7 @@ module CanvasOauth
|
|
8
8
|
|
9
9
|
def initialize(canvas_url, canvas_user_id, token, refresh_token, key, secret)
|
10
10
|
unless [key, secret].all?(&:present?)
|
11
|
-
raise "Invalid
|
11
|
+
raise "Invalid Qalam oAuth configuration"
|
12
12
|
end
|
13
13
|
|
14
14
|
self.refresh_token = refresh_token
|
@@ -19,6 +19,7 @@ module CanvasOauth
|
|
19
19
|
self.secret = secret
|
20
20
|
end
|
21
21
|
|
22
|
+
### START AUTH ###
|
22
23
|
def authenticated_request(method, *params)
|
23
24
|
params << {} if params.size == 1
|
24
25
|
|
@@ -53,6 +54,55 @@ module CanvasOauth
|
|
53
54
|
end
|
54
55
|
end
|
55
56
|
|
57
|
+
def auth_url(redirect_uri, oauth2_state)
|
58
|
+
"#{canvas_url}/login/oauth2/auth?client_id=#{key}&response_type=code&state=#{oauth2_state}&redirect_uri=#{redirect_uri}"
|
59
|
+
end
|
60
|
+
|
61
|
+
def qalam_auth_url(qalam_url, redirect_uri, oauth2_state)
|
62
|
+
"#{qalam_url}/login/oauth2/auth?client_id=#{key}&response_type=code&state=#{oauth2_state}&redirect_uri=#{redirect_uri}"
|
63
|
+
end
|
64
|
+
|
65
|
+
def get_access_token(code)
|
66
|
+
params = {
|
67
|
+
body: {
|
68
|
+
client_id: key,
|
69
|
+
client_secret: secret,
|
70
|
+
code: code
|
71
|
+
}
|
72
|
+
}
|
73
|
+
|
74
|
+
response = self.class.post '/login/oauth2/token', params
|
75
|
+
self.refresh_token = response['refresh_token']
|
76
|
+
self.token = response['access_token']
|
77
|
+
end
|
78
|
+
|
79
|
+
def get_access_token_by_refresh_token
|
80
|
+
params = {
|
81
|
+
body: {
|
82
|
+
grant_type: 'refresh_token',
|
83
|
+
client_id: key,
|
84
|
+
client_secret: secret,
|
85
|
+
refresh_token: refresh_token
|
86
|
+
}
|
87
|
+
}
|
88
|
+
|
89
|
+
response = self.class.post '/login/oauth2/token', params
|
90
|
+
self.token = response['access_token']
|
91
|
+
CanvasOauth::Authorization.update_token(refresh_token, token)
|
92
|
+
end
|
93
|
+
|
94
|
+
def authenticated_get(*params)
|
95
|
+
authenticated_request(:get, *params)
|
96
|
+
end
|
97
|
+
|
98
|
+
def authenticated_post(*params)
|
99
|
+
authenticated_request(:post, *params)
|
100
|
+
end
|
101
|
+
|
102
|
+
def authenticated_put(*params)
|
103
|
+
authenticated_request(:put, *params)
|
104
|
+
end
|
105
|
+
|
56
106
|
def paginated_get(url, params = {})
|
57
107
|
params[:query] ||= {}
|
58
108
|
params[:query][:per_page] = PER_PAGE
|
@@ -69,34 +119,25 @@ module CanvasOauth
|
|
69
119
|
|
70
120
|
all_pages
|
71
121
|
end
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
report = authenticated_get "/api/v1/accounts/#{account_id}/reports/#{report_type}/#{report['id']}"
|
79
|
-
end
|
80
|
-
|
81
|
-
if report['status'] == 'complete'
|
82
|
-
file_id = report['file_url'].match(/files\/([0-9]+)\/download/)[1]
|
83
|
-
file = get_file(file_id)
|
84
|
-
return hash_csv(self.class.get(file['url'], limit: 15, parser: DefaultUTF8Parser).parsed_response)
|
85
|
-
else
|
86
|
-
return report
|
87
|
-
end
|
122
|
+
### END AUTH ###
|
123
|
+
|
124
|
+
### HELPER METHODS ###
|
125
|
+
def canvas_url=(value)
|
126
|
+
@canvas_url = value
|
127
|
+
self.class.base_uri(value)
|
88
128
|
end
|
89
|
-
|
90
|
-
def
|
91
|
-
|
129
|
+
|
130
|
+
def canvas_user_id=(value)
|
131
|
+
@canvas_user_id = value
|
92
132
|
end
|
93
|
-
|
94
|
-
def
|
95
|
-
|
133
|
+
|
134
|
+
def hex_sis_id(name, value)
|
135
|
+
hex = value.unpack("H*")[0]
|
136
|
+
return "hex:#{name}:#{hex}"
|
96
137
|
end
|
97
138
|
|
98
|
-
def
|
99
|
-
|
139
|
+
def valid_page?(page)
|
140
|
+
page && page.size > 0
|
100
141
|
end
|
101
142
|
|
102
143
|
#Needs to be refactored to somewhere more generic
|
@@ -117,17 +158,61 @@ module CanvasOauth
|
|
117
158
|
|
118
159
|
return output
|
119
160
|
end
|
161
|
+
### END HELPER METHODS ###
|
162
|
+
|
163
|
+
### CANVAS API ###
|
164
|
+
# get_report
|
165
|
+
# get_file
|
166
|
+
# get_accounts_provisioning_report
|
167
|
+
# get_courses
|
168
|
+
# get_account
|
169
|
+
# get_account_sub_accounts
|
170
|
+
# get_account_courses
|
171
|
+
# get_account_users
|
172
|
+
# get_course
|
173
|
+
# get_section_enrollments
|
174
|
+
# get_user_enrollments
|
175
|
+
# get_course_users
|
176
|
+
# get_all_course_users
|
177
|
+
# get_course_teachers_and_tas
|
178
|
+
# get_course_students
|
179
|
+
# get_course_active_students
|
180
|
+
# get_section
|
181
|
+
# get_sections
|
182
|
+
# get_assignments
|
183
|
+
# get_assignment
|
184
|
+
# get_user_profile
|
185
|
+
# create_assignment
|
186
|
+
# update_assignment
|
187
|
+
# grade_assignment
|
188
|
+
# get_submission
|
189
|
+
# course_account_id
|
190
|
+
# root_account_id
|
191
|
+
# course_root_account_id
|
192
|
+
|
193
|
+
def get_report(account_id, report_type, params)
|
194
|
+
report = authenticated_post("/api/v1/accounts/#{account_id}/reports/#{report_type}", { body: params })
|
195
|
+
report = authenticated_get "/api/v1/accounts/#{account_id}/reports/#{report_type}/#{report['id']}"
|
196
|
+
while (report['status'] == 'created' || report['status'] == 'running')
|
197
|
+
sleep(4)
|
198
|
+
report = authenticated_get "/api/v1/accounts/#{account_id}/reports/#{report_type}/#{report['id']}"
|
199
|
+
end
|
120
200
|
|
121
|
-
|
122
|
-
|
201
|
+
if report['status'] == 'complete'
|
202
|
+
file_id = report['file_url'].match(/files\/([0-9]+)\/download/)[1]
|
203
|
+
file = get_file(file_id)
|
204
|
+
return hash_csv(self.class.get(file['url'], limit: 15, parser: DefaultUTF8Parser).parsed_response)
|
205
|
+
else
|
206
|
+
return report
|
207
|
+
end
|
123
208
|
end
|
124
209
|
|
125
|
-
def
|
126
|
-
|
210
|
+
def get_file(file_id)
|
211
|
+
authenticated_get "/api/v1/files/#{file_id}"
|
127
212
|
end
|
128
213
|
|
129
|
-
def
|
130
|
-
|
214
|
+
def get_accounts_provisioning_report(account_id)
|
215
|
+
get_report(account_id, :provisioning_csv, 'parameters[accounts]' => true)
|
131
216
|
end
|
132
217
|
|
133
218
|
def get_courses
|
@@ -146,7 +231,7 @@ module CanvasOauth
|
|
146
231
|
paginated_get "/api/v1/accounts/#{account_id}/courses"
|
147
232
|
end
|
148
233
|
|
149
|
-
def
|
234
|
+
def get_account_users(account_id)
|
150
235
|
paginated_get "/api/v1/accounts/#{account_id}/users"
|
151
236
|
end
|
152
237
|
|
@@ -234,59 +319,17 @@ module CanvasOauth
|
|
234
319
|
def course_root_account_id(course_id)
|
235
320
|
root_account_id(course_account_id(course_id))
|
236
321
|
end
|
322
|
+
### END CANVAS API ###
|
237
323
|
|
238
|
-
|
239
|
-
|
240
|
-
|
241
|
-
|
242
|
-
|
243
|
-
|
244
|
-
|
245
|
-
|
246
|
-
def get_access_token(code)
|
247
|
-
params = {
|
248
|
-
body: {
|
249
|
-
client_id: key,
|
250
|
-
client_secret: secret,
|
251
|
-
code: code
|
252
|
-
}
|
253
|
-
}
|
254
|
-
|
255
|
-
response = self.class.post '/login/oauth2/token', params
|
256
|
-
self.refresh_token = response['refresh_token']
|
257
|
-
self.token = response['access_token']
|
258
|
-
end
|
259
|
-
|
260
|
-
def get_access_token_by_refresh_token
|
261
|
-
params = {
|
262
|
-
body: {
|
263
|
-
grant_type: 'refresh_token',
|
264
|
-
client_id: key,
|
265
|
-
client_secret: secret,
|
266
|
-
refresh_token: refresh_token
|
267
|
-
}
|
268
|
-
}
|
324
|
+
### QALAM API ENDPOINTS ###
|
325
|
+
# get_canvas_user_profile
|
326
|
+
# get_course_active_pages
|
327
|
+
# course_external_tool_update
|
328
|
+
# account_external_tool_update
|
329
|
+
# get_school_details
|
330
|
+
# get_grade_students
|
331
|
+
# get_classroom_students
|
269
332
|
|
270
|
-
response = self.class.post '/login/oauth2/token', params
|
271
|
-
self.token = response['access_token']
|
272
|
-
CanvasOauth::Authorization.update_token(refresh_token, token)
|
273
|
-
end
|
274
|
-
|
275
|
-
def hex_sis_id(name, value)
|
276
|
-
hex = value.unpack("H*")[0]
|
277
|
-
return "hex:#{name}:#{hex}"
|
278
|
-
end
|
279
|
-
|
280
|
-
def canvas_url=(value)
|
281
|
-
@canvas_url = value
|
282
|
-
self.class.base_uri(value)
|
283
|
-
end
|
284
|
-
|
285
|
-
def canvas_user_id=(value)
|
286
|
-
@canvas_user_id = value
|
287
|
-
end
|
288
|
-
|
289
|
-
### QALAM ###
|
290
333
|
def get_canvas_user_profile
|
291
334
|
authenticated_get "/api/v1/users/#{canvas_user_id}/profile"
|
292
335
|
end
|
@@ -313,21 +356,14 @@ module CanvasOauth
|
|
313
356
|
authenticated_get "/api/v1/accounts/#{account_id}/school_details"
|
314
357
|
end
|
315
358
|
|
316
|
-
def
|
317
|
-
|
318
|
-
end
|
319
|
-
|
320
|
-
def get_school_account_by_course(course_id)
|
321
|
-
authenticated_get "/api/v1/courses/#{course_id}/school_account"
|
322
|
-
end
|
323
|
-
|
324
|
-
def get_students_by_grade(account_id, grade_id)
|
325
|
-
paginated_get "/api/v1/accounts/#{account_id}/students_by_grade/#{grade_id}"
|
359
|
+
def get_grade_students(account_id, grade_id)
|
360
|
+
paginated_get "/api/v1/accounts/#{account_id}/grade_students/#{grade_id}"
|
326
361
|
end
|
327
362
|
|
328
|
-
def
|
329
|
-
paginated_get "/api/v1/accounts/#{account_id}/
|
363
|
+
def get_classroom_students(account_id, class_id)
|
364
|
+
paginated_get "/api/v1/accounts/#{account_id}/classroom_students/#{class_id}"
|
330
365
|
end
|
366
|
+
### END QALAM API ###
|
331
367
|
end
|
332
368
|
|
333
369
|
class CanvasApi::Unauthorized < StandardError ; end
|
File without changes
|
File without changes
|
@@ -13,7 +13,7 @@ module CanvasOauth
|
|
13
13
|
|
14
14
|
def self.setup!
|
15
15
|
if File.exists?(config_file)
|
16
|
-
Rails.logger.info "Initializing
|
16
|
+
Rails.logger.info "Initializing Qalam using configuration in #{config_file}"
|
17
17
|
config = load_config
|
18
18
|
self.key = config['key']
|
19
19
|
self.secret = config['secret']
|
@@ -21,13 +21,13 @@ module CanvasOauth
|
|
21
21
|
Rails.logger.info "\n> Initializing Key #{config['key']} - Secret #{config['secret']}\n".green
|
22
22
|
|
23
23
|
elsif ENV['CANVAS_KEY'].present? && ENV['CANVAS_SECRET'].present?
|
24
|
-
Rails.logger.info "Initializing
|
24
|
+
Rails.logger.info "Initializing Qalam using environment vars CANVAS_KEY and CANVAS_SECRET"
|
25
25
|
self.key = ENV['CANVAS_KEY']
|
26
26
|
self.secret = ENV['CANVAS_SECRET']
|
27
27
|
|
28
28
|
Rails.logger.info "\n> Initializing Key #{ENV['CANVAS_KEY']} - Secret #{ENV['CANVAS_SECRET']}\n".green
|
29
29
|
else
|
30
|
-
warn "Warning:
|
30
|
+
warn "Warning: Qalam key and secret not configured (RAILS_ENV = #{ENV['RAILS_ENV']})."
|
31
31
|
end
|
32
32
|
end
|
33
33
|
end
|
data/lib/canvas_oauth/config.rb
CHANGED
File without changes
|
File without changes
|
data/lib/canvas_oauth/engine.rb
CHANGED
File without changes
|
data/lib/canvas_oauth/version.rb
CHANGED
File without changes
|
File without changes
|
data/spec/dummy/README.rdoc
CHANGED
File without changes
|
data/spec/dummy/Rakefile
CHANGED
File without changes
|
File without changes
|
File without changes
|
data/spec/dummy/config.ru
CHANGED
File without changes
|
File without changes
|
data/spec/dummy/config/boot.rb
CHANGED
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
data/spec/dummy/config/routes.rb
CHANGED
File without changes
|
File without changes
|
data/spec/dummy/db/migrate/20160711200737_create_canvas_oauth_authorizations.canvas_oauth.rb
CHANGED
File without changes
|
data/spec/dummy/db/schema.rb
CHANGED
File without changes
|
data/spec/dummy/db/test.sqlite3
CHANGED
File without changes
|
File without changes
|
data/spec/dummy/log/test.log
CHANGED
File without changes
|
data/spec/dummy/public/404.html
CHANGED
File without changes
|
data/spec/dummy/public/422.html
CHANGED
File without changes
|
data/spec/dummy/public/500.html
CHANGED
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
data/spec/spec_helper.rb
CHANGED
File without changes
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: qalam_oauth_engine
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 3.0.
|
4
|
+
version: 3.0.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Dave Donahue
|
@@ -11,7 +11,7 @@ authors:
|
|
11
11
|
autorequire:
|
12
12
|
bindir: bin
|
13
13
|
cert_chain: []
|
14
|
-
date: 2021-
|
14
|
+
date: 2021-07-28 00:00:00.000000000 Z
|
15
15
|
dependencies:
|
16
16
|
- !ruby/object:Gem::Dependency
|
17
17
|
name: httparty
|
@@ -330,7 +330,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
330
330
|
- !ruby/object:Gem::Version
|
331
331
|
version: '0'
|
332
332
|
requirements: []
|
333
|
-
rubygems_version: 3.2.
|
333
|
+
rubygems_version: 3.2.21
|
334
334
|
signing_key:
|
335
335
|
specification_version: 4
|
336
336
|
summary: CanvasOauth is a mountable engine for handling the oauth workflow with canvas
|