inst_access 0.1.2 → 0.4.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 12fea04283e0ab7de90ccba958ea4b9493609a13ee76348f82cd7ba3d7130c05
4
- data.tar.gz: aa5acc71501312bd6e2a565e54f34165a52452834afe0f9839a2042468edac69
3
+ metadata.gz: f3f8f9627e9866878600ebfffa114229879693c401e03a07f024c9ecc7aa4567
4
+ data.tar.gz: 95a2ad12a7fbb4392c6828353734ad24a43cb10056c822b50d6234c4f8f2223d
5
5
  SHA512:
6
- metadata.gz: 7ec774b0de8614005a076ebb1446276ddc207d58f709d74acefa9edbffb5bcf17454e4be6e13e41e8cc1f227bae5e5c646d30aec67ca20f89d936f6fdf2086c5
7
- data.tar.gz: c50c9bf65142c3e72b10eefb55cd658ccfac651f64e98dbb8c4103f301a4edf3effdedfcac5cdb74009274e282186179b9be30d6e416a08978a670a7444d66db
6
+ metadata.gz: 1946b0ac1c71312c08d2e931f542e3e35119d3e26b4590c03f260bfec093d947cae388125e935ab03d1e63cbb2c06273ed9ed7da67bfba54406d523b78142988
7
+ data.tar.gz: 650914d4e10bc474b71146351956ce903b318efb32c453da9ea697c3aac5cf0f840d2e455982f1abc6fa3ebf893857fef3db1fc990a8febd278e1b768034bab9
@@ -54,6 +54,18 @@ module InstAccess
54
54
  jwt_payload[:region]
55
55
  end
56
56
 
57
+ def client_id
58
+ jwt_payload[:client_id]
59
+ end
60
+
61
+ def instructure_service?
62
+ jwt_payload[:instructure_service] == true
63
+ end
64
+
65
+ def jti
66
+ jwt_payload[:jti]
67
+ end
68
+
57
69
  def to_token_string
58
70
  jwe = to_jws.encrypt(InstAccess.config.encryption_key, ENCRYPTION_ALGO, ENCRYPTION_METHOD)
59
71
  jwe.to_s
@@ -87,7 +99,9 @@ module InstAccess
87
99
  real_user_shard_id: nil,
88
100
  user_global_id: nil,
89
101
  real_user_global_id: nil,
90
- region: nil
102
+ region: nil,
103
+ client_id: nil,
104
+ instructure_service: nil
91
105
  )
92
106
  raise ArgumentError, 'Must provide user uuid and account uuid' if user_uuid.blank? || account_uuid.blank?
93
107
 
@@ -95,6 +109,7 @@ module InstAccess
95
109
 
96
110
  payload = {
97
111
  iss: ISSUER,
112
+ jti: SecureRandom.uuid,
98
113
  iat: now,
99
114
  exp: now + 1.hour.to_i,
100
115
  sub: user_uuid,
@@ -104,7 +119,9 @@ module InstAccess
104
119
  masq_shard: real_user_shard_id,
105
120
  debug_user_global_id: user_global_id&.to_s,
106
121
  debug_masq_global_id: real_user_global_id&.to_s,
107
- region: region
122
+ region: region,
123
+ client_id: client_id,
124
+ instructure_service: instructure_service
108
125
  }.compact
109
126
 
110
127
  new(payload)
@@ -0,0 +1,23 @@
1
+ # frozen_string_literal: true
2
+
3
+ #
4
+ # Copyright (C) 2023 - present Instructure, Inc.
5
+ #
6
+ # This file is part of Canvas.
7
+ #
8
+ # Canvas is free software: you can redistribute it and/or modify it under
9
+ # the terms of the GNU Affero General Public License as published by the Free
10
+ # Software Foundation, version 3 of the License.
11
+ #
12
+ # Canvas is distributed in the hope that it will be useful, but WITHOUT ANY
13
+ # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
14
+ # A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
15
+ # details.
16
+ #
17
+ # You should have received a copy of the GNU Affero General Public License along
18
+ # with this program. If not, see <http://www.gnu.org/licenses/>.
19
+ #
20
+
21
+ module InstAccess
22
+ VERSION = '0.4.0'
23
+ end
data/lib/inst_access.rb CHANGED
@@ -23,6 +23,7 @@ require 'json/jwt'
23
23
  require 'inst_access/errors'
24
24
  require 'inst_access/config'
25
25
  require 'inst_access/token'
26
+ require 'inst_access/version'
26
27
 
27
28
  module InstAccess
28
29
  class << self
@@ -85,12 +85,35 @@ describe InstAccess::Token do
85
85
  canvas_domain: 'z.instructure.com',
86
86
  real_user_uuid: 'masq-id',
87
87
  real_user_shard_id: 5,
88
- region: 'us-west-2'
88
+ region: 'us-west-2',
89
+ client_id: 'client-id',
90
+ instructure_service: true
89
91
  )
90
92
  expect(id.canvas_domain).to eq('z.instructure.com')
91
93
  expect(id.masquerading_user_uuid).to eq('masq-id')
92
94
  expect(id.masquerading_user_shard_id).to eq(5)
93
95
  expect(id.region).to eq('us-west-2')
96
+ expect(id.client_id).to eq('client-id')
97
+ expect(id.instructure_service?).to eq true
98
+ end
99
+
100
+ it 'generates a unique jti' do
101
+ uuid = SecureRandom.uuid
102
+
103
+ allow(SecureRandom).to receive(:uuid).and_return uuid
104
+
105
+ id = described_class.for_user(
106
+ user_uuid: 'user-uuid',
107
+ account_uuid: 'acct-uuid',
108
+ canvas_domain: 'z.instructure.com',
109
+ real_user_uuid: 'masq-id',
110
+ real_user_shard_id: 5,
111
+ region: 'us-west-2',
112
+ client_id: 'client-id',
113
+ instructure_service: true
114
+ )
115
+
116
+ expect(id.jti).to eq uuid
94
117
  end
95
118
 
96
119
  it 'includes global id debug info if given' do
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: inst_access
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Michael Ziwisky
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-07-19 00:00:00.000000000 Z
11
+ date: 2023-09-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -28,16 +28,16 @@ dependencies:
28
28
  name: json-jwt
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - "~>"
31
+ - - '='
32
32
  - !ruby/object:Gem::Version
33
- version: '1.13'
33
+ version: 1.13.0
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
- - - "~>"
38
+ - - '='
39
39
  - !ruby/object:Gem::Version
40
- version: '1.13'
40
+ version: 1.13.0
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: bundler
43
43
  requirement: !ruby/object:Gem::Requirement
@@ -150,7 +150,7 @@ dependencies:
150
150
  - - ">="
151
151
  - !ruby/object:Gem::Version
152
152
  version: '0'
153
- description:
153
+ description:
154
154
  email:
155
155
  - mziwisky@instructure.com
156
156
  executables: []
@@ -161,6 +161,7 @@ files:
161
161
  - lib/inst_access/config.rb
162
162
  - lib/inst_access/errors.rb
163
163
  - lib/inst_access/token.rb
164
+ - lib/inst_access/version.rb
164
165
  - spec/initialize_coverage.rb
165
166
  - spec/inst_access/inst_access_spec.rb
166
167
  - spec/inst_access/token_spec.rb
@@ -169,7 +170,7 @@ files:
169
170
  homepage: http://github.com/instructure/inst_access
170
171
  licenses: []
171
172
  metadata: {}
172
- post_install_message:
173
+ post_install_message:
173
174
  rdoc_options: []
174
175
  require_paths:
175
176
  - lib
@@ -184,8 +185,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
184
185
  - !ruby/object:Gem::Version
185
186
  version: '0'
186
187
  requirements: []
187
- rubygems_version: 3.1.6
188
- signing_key:
188
+ rubygems_version: 3.2.6
189
+ signing_key:
189
190
  specification_version: 4
190
191
  summary: Generation, parsing, and validation of Instructure access tokens
191
192
  test_files: