Module: InstAccess

Defined in:
lib/inst_access/token.rb,
lib/inst_access.rb,
lib/inst_access/config.rb,
lib/inst_access/errors.rb

Overview

Copyright © 2021 - present Instructure, Inc.

This file is part of Canvas.

Canvas is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License as published by the Free Software Foundation, version 3 of the License.

Canvas is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more details.

You should have received a copy of the GNU Affero General Public License along with this program. If not, see <www.gnu.org/licenses/>.

Defined Under Namespace

Classes: Config, ConfigError, Error, InvalidToken, Token, TokenExpired

Class Method Summary collapse

Class Method Details

.configObject



48
49
50
# File 'lib/inst_access.rb', line 48

def config
  @config || raise(ConfigError, 'InstAccess is not configured!')
end

.configure(signing_key:, encryption_key: nil) ⇒ Object

signing_key is required. if you are going to be producing (and therefore signing) tokens, this needs to be an RSA private key. if you’re just consuming tokens, it can be the RSA public key corresponding to the private key that signed them. encryption_key is only required if you are going to be producing tokens.



34
35
36
# File 'lib/inst_access.rb', line 34

def configure(signing_key:, encryption_key: nil)
  @config = Config.new(signing_key, encryption_key)
end

.with_config(signing_key:, encryption_key: nil) ⇒ Object

set a configuration only for the duration of the given block, then revert it. useful for testing.



40
41
42
43
44
45
46
# File 'lib/inst_access.rb', line 40

def with_config(signing_key:, encryption_key: nil)
  old_config = @config
  configure(signing_key: signing_key, encryption_key: encryption_key)
  yield
ensure
  @config = old_config
end