canvas-embed 0.1.1 → 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.
- checksums.yaml +4 -4
- data/README.md +40 -0
- data/lib/canvas/embed.rb +28 -0
- metadata +5 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e185250539e0fd29e6b9e3324986a044e7c0432017b8cce37a83a3c40a6a8d03
|
4
|
+
data.tar.gz: 7ff8320e2b3648c934e0cb14f41aab09a65f66df2989e642af5d9232205576a0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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
|
+
```
|
data/lib/canvas/embed.rb
ADDED
@@ -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,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: canvas-embed
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Will Pride
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2023-11-
|
11
|
+
date: 2023-11-07 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rbnacl
|
@@ -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
|