canvas-embed 0.1.6 → 0.1.7

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 3ed39f8027511445d28514cde191bade34d5b4101814dfb4bd7307d5b7eb51e4
4
- data.tar.gz: 7528eaaf4db9c5c77d3be5a6a50ba40eb1321e9805b119b3144300ea020cd861
3
+ metadata.gz: 45b64ffaefba9ed0079b7d68ce049ea9b13f43e33b1b16af374eece5f2d602c2
4
+ data.tar.gz: 06712ec1051c757a7835ab7df4c6d47728a4bc99f6a0054d2d42b4fb606d162e
5
5
  SHA512:
6
- metadata.gz: a277e1fe0976095609dea6a27e35101028eeec6c8cb0129e05b91a61c8b40eab15c8a445189c9219915355d58722f6cdce6d4ae0998bfb80bf2158a1d1fd0580
7
- data.tar.gz: edacd70f37ed8c97e9a4a045c795e5608ad967bf088cd5b9e6818a00be9889dbbb451eb5f422c0bd5fae1ab120331ea442b77533804867475109d06d8654c833
6
+ metadata.gz: dd3ee766aff62d4420fda59ab2e4a274a3cf28ebb00d5364b186c9476141fa350679db9506c45abab458c1f948d95409fa731300ff4c8700a982d3ae68d9992c
7
+ data.tar.gz: 8eb0765d2c8be6e8a5fd51e15637ad1a0c3692175a0ae3d89f1759ad093c40bf4d8503b2fbd1bedb41271c060503570d6726a1c30d1e88c46e41bb5728dcad3f
data/Gemfile CHANGED
@@ -5,6 +5,8 @@ source 'https://rubygems.org'
5
5
  # Specify your gem's dependencies in canvas-embed.gemspec
6
6
  gemspec
7
7
 
8
+ gem 'canvas-embed'
9
+
8
10
  gem 'rake', '~> 13.1'
9
11
 
10
12
  gem 'rspec', '~> 3.0'
data/README.md CHANGED
@@ -10,6 +10,18 @@ If any scopes are required by your charts that are not present in the scopes pay
10
10
 
11
11
  You can view how this Gem is used in a sample rails app in the `example/` directory
12
12
 
13
+ # Usage
14
+
15
+ Add `gem 'canvas-embed'` to your Gemfile, then:
16
+
17
+ ```
18
+ # key is the private key from Canvas
19
+ # scopes is the Hash of scopes to grant the user
20
+ # expiration_seconds is the duration in seconds for the token to be valid (default is one hour)
21
+ # user_id is an optional user identifier that will be used in Canvas' logging
22
+ Canvas::Embed.generate_embed_token(key, scopes, expiration_seconds, user_id)
23
+ ```
24
+
13
25
  # Running tests
14
26
 
15
27
  ```
data/example/Gemfile CHANGED
@@ -7,7 +7,7 @@ ruby '3.2.2'
7
7
  # Bundle edge Rails instead: gem "rails", github: "rails/rails", branch: "main"
8
8
  gem 'rails', '~> 7.1.1'
9
9
 
10
- gem 'canvas-embed', '~> 0.1.4'
10
+ gem 'canvas-embed', '~> 0.1.6'
11
11
 
12
12
  gem 'rack-cors'
13
13
 
data/example/Gemfile.lock CHANGED
@@ -82,7 +82,7 @@ GEM
82
82
  bootsnap (1.17.0)
83
83
  msgpack (~> 1.2)
84
84
  builder (3.2.4)
85
- canvas-embed (0.1.5)
85
+ canvas-embed (0.1.6)
86
86
  rbnacl (~> 7.1.1)
87
87
  capybara (3.39.2)
88
88
  addressable
@@ -251,7 +251,7 @@ PLATFORMS
251
251
 
252
252
  DEPENDENCIES
253
253
  bootsnap
254
- canvas-embed (~> 0.1.4)
254
+ canvas-embed (~> 0.1.6)
255
255
  capybara
256
256
  debug
257
257
  importmap-rails
data/example/README.md CHANGED
@@ -10,7 +10,7 @@ After running `bundle install` you can start the Rails server with
10
10
  CANVAS_SIGNING_KEY=[your signing key] bin/rails server
11
11
  ```
12
12
 
13
- This serves a GET endpoint `generate_token?scopes=[scopes]` where scopes are the scopes you want included in the generated token.
13
+ This serves a GET endpoint `generate_embed_token?scopes=[scopes]` where scopes are the scopes you want included in the generated token.
14
14
 
15
15
 
16
16
  This endpoint is used in the [React component](https://github.com/canvas/embeds/tree/main/react) to view embedded Canvas charts as they will appear to your users.
@@ -1,9 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- include Canvas::Embed
4
-
5
3
  class ApplicationController < ActionController::Base
6
- def generate_token
4
+ def generate_embed_token
7
5
  # this is the secret signing key from Canvas
8
6
  key_hex = ENV['CANVAS_SIGNING_KEY']
9
7
  # this should be updated to include the scopes needed for your charts and that are
@@ -13,7 +11,14 @@ class ApplicationController < ActionController::Base
13
11
  rescue StandardError
14
12
  return render json: { 'message' => 'Scopes were not valid JSON' }, status: 500
15
13
  end
16
- token = Canvas::Embed.generate_token(key_hex, scopes, 7200, "usr_test123")
14
+ token = Canvas::Embed.generate_embed_token(key_hex, scopes, 7200, "usr_test123")
15
+ render json: { 'token' => token }
16
+ end
17
+ def generate_login_token
18
+ # this is the secret signing key from Canvas
19
+ key_hex = ENV['CANVAS_SIGNING_KEY']
20
+ email = params[:email]
21
+ token = Canvas::Embed.generate_login_token(key_hex, email)
17
22
  render json: { 'token' => token }
18
23
  end
19
24
  end
@@ -6,7 +6,8 @@ Rails.application.routes.draw do
6
6
  # Reveal health status on /up that returns 200 if the app boots with no exceptions, otherwise 500.
7
7
  # Can be used by load balancers and uptime monitors to verify that the app is live.
8
8
  get 'up' => 'rails/health#show', as: :rails_health_check
9
- get '/generate_token', to: 'application#generate_token'
9
+ get '/generate_embed_token', to: 'application#generate_embed_token'
10
+ get '/generate_login_token', to: 'application#generate_login_token'
10
11
 
11
12
  # Defines the root path route ("/")
12
13
  # root "posts#index"