qalam_oauth_engine 3.0.3 → 3.0.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/app/controllers/canvas_oauth/canvas_controller.rb +10 -1
- data/app/models/canvas_oauth/authorization.rb +10 -1
- data/db/migrate/20121121005358_create_canvas_oauth_authorizations.rb +1 -0
- data/lib/canvas_oauth/canvas_api.rb +6 -1
- data/lib/canvas_oauth/canvas_api_extensions.rb +3 -2
- data/lib/canvas_oauth/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e153aaa7541aee767fe47cb0824831482a12f392f1bd87803ee4ad4703e7d30f
|
4
|
+
data.tar.gz: '0494829ca2a3a9d94c7ddee7ca5b853de2df985e74e1d3f142f1d805578826ad'
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2bca130d4a82b30db36ebb3fb1a6208db2b7cc6350cd97e8c1a9e9ada3498e0d3f431f2c4f626db35bfeb03e540e27a1b9e5543487380da2b9b73783b4b6d0cc
|
7
|
+
data.tar.gz: 91a7d377612aa1e3d5036e730348224c7c0d0f60f0aa1635d4c4f1f6f6d7d847f6c9f40430bb3538d4e6cb8638893d2b6ccf0f631aebdcd6768953cb1ab293df
|
@@ -5,8 +5,9 @@ module CanvasOauth
|
|
5
5
|
def oauth
|
6
6
|
if verify_oauth2_state(params[:state]) && params[:code]
|
7
7
|
if token = canvas.get_access_token(params[:code])
|
8
|
+
set_root_account
|
8
9
|
refresh_token = canvas.refresh_token
|
9
|
-
if CanvasOauth::Authorization.cache_token(token, refresh_token, user_id, tool_consumer_instance_guid)
|
10
|
+
if CanvasOauth::Authorization.cache_token(token, refresh_token, user_id, @root_account_id, tool_consumer_instance_guid)
|
10
11
|
redirect_to main_app.root_path
|
11
12
|
else
|
12
13
|
render plain: "Error: unable to save token"
|
@@ -23,4 +24,12 @@ module CanvasOauth
|
|
23
24
|
callback_state.present? && callback_state == session.delete(:oauth2_state)
|
24
25
|
end
|
25
26
|
end
|
27
|
+
|
28
|
+
def set_root_account
|
29
|
+
if current_account_id
|
30
|
+
@root_account_id = canvas.root_account_id(current_account_id)
|
31
|
+
elsif current_course_id
|
32
|
+
@root_account_id = canvas.course_root_account_id(current_course_id)
|
33
|
+
end
|
34
|
+
end
|
26
35
|
end
|
@@ -2,16 +2,25 @@ module CanvasOauth
|
|
2
2
|
class Authorization < ActiveRecord::Base
|
3
3
|
validates :canvas_user_id, :token, :refresh_token, :last_used_at, presence: true
|
4
4
|
|
5
|
-
def self.cache_token(token, refresh_token, user_id, tool_consumer_instance_guid)
|
5
|
+
def self.cache_token(token, refresh_token, user_id, account_id, tool_consumer_instance_guid)
|
6
6
|
create do |t|
|
7
7
|
t.token = token
|
8
8
|
t.refresh_token = refresh_token
|
9
9
|
t.canvas_user_id = user_id
|
10
|
+
t.canvas_root_account_id = account_id
|
10
11
|
t.tool_consumer_instance_guid = tool_consumer_instance_guid
|
11
12
|
t.last_used_at = Time.now
|
12
13
|
end
|
13
14
|
end
|
14
15
|
|
16
|
+
def self.fetch_account(user_id, tool_consumer_instance_guid)
|
17
|
+
user_accounts = where(canvas_user_id: user_id, tool_consumer_instance_guid: tool_consumer_instance_guid).order("created_at DESC")
|
18
|
+
if canvas_auth = user_accounts.first
|
19
|
+
canvas_auth.update_attribute(:last_used_at, Time.now)
|
20
|
+
return canvas_auth.canvas_root_account_id
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
15
24
|
def self.fetch_token(user_id, tool_consumer_instance_guid)
|
16
25
|
user_tokens = where(canvas_user_id: user_id, tool_consumer_instance_guid: tool_consumer_instance_guid).order("created_at DESC")
|
17
26
|
if canvas_auth = user_tokens.first
|
@@ -2,6 +2,7 @@ class CreateCanvasOauthAuthorizations < ActiveRecord::Migration[4.2]
|
|
2
2
|
def change
|
3
3
|
create_table "canvas_oauth_authorizations", :force => true do |t|
|
4
4
|
t.integer "canvas_user_id", :limit => 8
|
5
|
+
t.integer "canvas_root_account_id", :limit => 8
|
5
6
|
t.string "tool_consumer_instance_guid", :null => false
|
6
7
|
t.string "token"
|
7
8
|
t.string "refresh_token"
|
@@ -6,7 +6,7 @@ module CanvasOauth
|
|
6
6
|
attr_accessor :token, :refresh_token, :key, :secret
|
7
7
|
attr_reader :canvas_url, :canvas_user_id
|
8
8
|
|
9
|
-
def initialize(canvas_url, canvas_user_id, token, refresh_token, key, secret)
|
9
|
+
def initialize(canvas_url, canvas_user_id, canvas_root_account_id, token, refresh_token, key, secret)
|
10
10
|
unless [key, secret].all?(&:present?)
|
11
11
|
raise "Invalid Qalam oAuth configuration"
|
12
12
|
end
|
@@ -14,6 +14,7 @@ module CanvasOauth
|
|
14
14
|
self.refresh_token = refresh_token
|
15
15
|
self.canvas_url = canvas_url
|
16
16
|
self.canvas_user_id = canvas_user_id
|
17
|
+
self.canvas_root_account_id = canvas_root_account_id
|
17
18
|
self.token = token
|
18
19
|
self.key = key
|
19
20
|
self.secret = secret
|
@@ -130,6 +131,10 @@ module CanvasOauth
|
|
130
131
|
def canvas_user_id=(value)
|
131
132
|
@canvas_user_id = value
|
132
133
|
end
|
134
|
+
|
135
|
+
def canvas_root_account_id=(value)
|
136
|
+
@canvas_root_account_id = value
|
137
|
+
end
|
133
138
|
|
134
139
|
def hex_sis_id(name, value)
|
135
140
|
hex = value.unpack("H*")[0]
|
@@ -1,11 +1,12 @@
|
|
1
1
|
module CanvasOauth
|
2
2
|
class CanvasApiExtensions
|
3
3
|
def self.build(canvas_url, user_id, tool_consumer_instance_guid)
|
4
|
-
|
4
|
+
account_id = CanvasOauth::Authorization.fetch_ccount(user_id, tool_consumer_instance_guid)
|
5
5
|
token = CanvasOauth::Authorization.fetch_token(user_id, tool_consumer_instance_guid)
|
6
|
+
refresh_token = CanvasOauth::Authorization.fetch_refresh_token(user_id, tool_consumer_instance_guid)
|
6
7
|
canvas_key = ((CanvasLtiKey.table_exists? && CanvasLtiKey.find_by(canvas_url: canvas_url)&.key) or CanvasConfig.key)
|
7
8
|
canvas_secret = ((CanvasLtiKey.table_exists? && CanvasLtiKey.find_by(key: canvas_key, canvas_url: canvas_url)&.secret) or CanvasConfig.secret)
|
8
|
-
CanvasApi.new(canvas_url, user_id, token, refresh_token, canvas_key, canvas_secret)
|
9
|
+
CanvasApi.new(canvas_url, user_id, account_id, token, refresh_token, canvas_key, canvas_secret)
|
9
10
|
end
|
10
11
|
end
|
11
12
|
end
|
data/lib/canvas_oauth/version.rb
CHANGED
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.4
|
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-08-
|
14
|
+
date: 2021-08-22 00:00:00.000000000 Z
|
15
15
|
dependencies:
|
16
16
|
- !ruby/object:Gem::Dependency
|
17
17
|
name: httparty
|