canvas-embed 0.1.2 → 0.1.3

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.
Files changed (4) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +40 -0
  3. data/lib/canvas/embed.rb +28 -0
  4. metadata +4 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 2ae4f7ad4a25488a444dea932b5846ab57a78e86c6383f579c89e70fc668eb0c
4
- data.tar.gz: 414c3d87b5f1203fa1a877118c77b0e87d744231c568881c1ae1a2afa76f146f
3
+ metadata.gz: e185250539e0fd29e6b9e3324986a044e7c0432017b8cce37a83a3c40a6a8d03
4
+ data.tar.gz: 7ff8320e2b3648c934e0cb14f41aab09a65f66df2989e642af5d9232205576a0
5
5
  SHA512:
6
- metadata.gz: d9aca4c63145661dcd1f504d5107f5c86139e0f1245247dd1ad93a8fd8b990f8dc34367cf783d53544011f07fa2ff7740d375f20a9cb2bceb6be35a849aef30a
7
- data.tar.gz: ebb161e1a0af4aa2d90baaadb65108cb244747a75fae74b729a09ddedf4b313f9867f93209f8380caa13d0b4171412e6321bded36d5949cb66127b42cc8c77e5
6
+ metadata.gz: bfcf03d22c7f2458af4a9bee05dd9035413648e51b12f951527a22c2360c2f47239577af721ee24bfd9df067019df9074f27a78c829c7d469a10f8537ce3cd9f
7
+ data.tar.gz: 8bf90b19df7368243da97e30e8f127a5b2d45ac58619cddcdd4098b2810e5df1d9d784001bc53940493aa23728a9c2031be2e7a1c8dd771ba7b5ce5e1235fe82
data/README.md ADDED
@@ -0,0 +1,40 @@
1
+ # Canvas::Embed
2
+
3
+ This Gem allows you to generate signed tokens that grant access to your Canvas embeds.
4
+
5
+ Your application frontend can then use these tokens in the Canvas [React component](https://github.com/canvas/embeds/tree/main/react) to display your Canvas embeds in your application.
6
+
7
+ Each token should be configured with the set of scopes that are approriate for the user, granting them access to only their data.
8
+
9
+ If any scopes are required by your charts that are not present in the scopes payload, the request will fail.
10
+
11
+ You can view how this Gem is used in a sample rails app in the `example/` directory
12
+
13
+ # Running
14
+
15
+ ```
16
+ bin/rails server
17
+ ```
18
+
19
+ This application expects the key in the CANVAS_SIGNING_KEY variable. You can set this by running:
20
+
21
+ ```
22
+ CANVAS_SIGNING_KEY=emk_HgwRqhyt.f0533f95ed220910218667124cac2116fsse11daf2aa1ff9938f7fde7a16c203 bin/rails server
23
+ ```
24
+
25
+ # Running tests
26
+
27
+ ```
28
+ rspec
29
+ ```
30
+
31
+ # Canvas publishing
32
+
33
+ ```
34
+ # increment the version in version.rb
35
+ # build the new gem
36
+ rake build
37
+ # outputs new gem path eg 'canvas-embed 0.1.1 built to pkg/canvas-embed-0.1.1.gem'
38
+ # publish the new gem (need rubygems.org access) from the path above
39
+ gem push pkg/canvas-embed-0.1.1.gem
40
+ ```
@@ -0,0 +1,28 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "embed/version"
4
+ require 'json'
5
+ require 'rbnacl'
6
+ require "base64"
7
+
8
+ module Canvas
9
+ module Embed
10
+ extend self
11
+ def generate_token(private_key, scopes)
12
+ # token consists of an id and the signing key
13
+ key_id, key = private_key.split('.')
14
+ # transform signing key hex into bytes
15
+ key_bytes = [key].pack('H*')
16
+ secret_box = RbNaCl::SecretBox.new(key_bytes)
17
+ nonce = RbNaCl::Random.random_bytes(secret_box.nonce_bytes)
18
+ message = { "scopes" => scopes }.to_json
19
+ ciphertext = secret_box.encrypt(nonce, message)
20
+ # transform bytes into hex
21
+ unpacked_message = ciphertext.unpack('H*').first
22
+ unpacked_nonce = nonce.unpack('H*').first
23
+ token = { "message" => unpacked_message, "nonce" => unpacked_nonce, "keyId" => key_id }.to_json;
24
+ # strict for no newlines
25
+ Base64.strict_encode64(token)
26
+ end
27
+ end
28
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: canvas-embed
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.1.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Will Pride
@@ -60,7 +60,9 @@ email:
60
60
  executables: []
61
61
  extensions: []
62
62
  extra_rdoc_files: []
63
- files: []
63
+ files:
64
+ - README.md
65
+ - lib/canvas/embed.rb
64
66
  homepage: https://github.com/canvas/embeds
65
67
  licenses:
66
68
  - MIT