omniauth-canvas 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore ADDED
@@ -0,0 +1,18 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
18
+ *.swp
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --colour
2
+ --format=progress
data/.rvmrc ADDED
@@ -0,0 +1,48 @@
1
+ #!/usr/bin/env bash
2
+
3
+ # This is an RVM Project .rvmrc file, used to automatically load the ruby
4
+ # development environment upon cd'ing into the directory
5
+
6
+ # First we specify our desired <ruby>[@<gemset>], the @gemset name is optional,
7
+ # Only full ruby name is supported here, for short names use:
8
+ # echo "rvm use 1.9.3" > .rvmrc
9
+ environment_id="ruby-1.9.3-p194@omniauth-canvas"
10
+
11
+ # Uncomment the following lines if you want to verify rvm version per project
12
+ # rvmrc_rvm_version="1.12.4 ()" # 1.10.1 seams as a safe start
13
+ # eval "$(echo ${rvm_version}.${rvmrc_rvm_version} | awk -F. '{print "[[ "$1*65536+$2*256+$3" -ge "$4*65536+$5*256+$6" ]]"}' )" || {
14
+ # echo "This .rvmrc file requires at least RVM ${rvmrc_rvm_version}, aborting loading."
15
+ # return 1
16
+ # }
17
+
18
+ # First we attempt to load the desired environment directly from the environment
19
+ # file. This is very fast and efficient compared to running through the entire
20
+ # CLI and selector. If you want feedback on which environment was used then
21
+ # insert the word 'use' after --create as this triggers verbose mode.
22
+ if [[ -d "${rvm_path:-$HOME/.rvm}/environments"
23
+ && -s "${rvm_path:-$HOME/.rvm}/environments/$environment_id" ]]
24
+ then
25
+ \. "${rvm_path:-$HOME/.rvm}/environments/$environment_id"
26
+ [[ -s "${rvm_path:-$HOME/.rvm}/hooks/after_use" ]] &&
27
+ \. "${rvm_path:-$HOME/.rvm}/hooks/after_use" || true
28
+ else
29
+ # If the environment file has not yet been created, use the RVM CLI to select.
30
+ rvm --create "$environment_id" || {
31
+ echo "Failed to create RVM environment '${environment_id}'."
32
+ return 1
33
+ }
34
+ fi
35
+
36
+ # If you use bundler, this might be useful to you:
37
+ # if [[ -s Gemfile ]] && {
38
+ # ! builtin command -v bundle >/dev/null ||
39
+ # builtin command -v bundle | grep $rvm_path/bin/bundle >/dev/null
40
+ # }
41
+ # then
42
+ # printf "%b" "The rubygem 'bundler' is not installed. Installing it now.\n"
43
+ # gem install bundler
44
+ # fi
45
+ # if [[ -s Gemfile ]] && builtin command -v bundle >/dev/null
46
+ # then
47
+ # bundle install | grep -vE '^Using|Your bundle is complete'
48
+ # fi
data/Gemfile ADDED
@@ -0,0 +1,19 @@
1
+ # clean up:
2
+ # rm -rf ~/.bundle/ ~/.gem/; rm -rf $GEM_HOME/bundler/ $GEM_HOME/cache/bundler/; rm -rf .bundle/; rm -rf vendor/cache/; rm -rf Gemfile.lock
3
+
4
+ source 'http://rubygems.org'
5
+
6
+ gemspec
7
+
8
+ group :development, :test do
9
+ gem 'growl'
10
+ gem 'rspec', '~>2.8.0'
11
+ gem 'guard'
12
+ gem 'guard-rspec'
13
+ gem 'guard-bundler'
14
+ gem 'growl'
15
+ gem 'rb-fsevent'
16
+ gem 'simplecov'
17
+ gem 'debugger'
18
+ gem 'rack-test'
19
+ end
data/Guardfile ADDED
@@ -0,0 +1,11 @@
1
+ guard 'rspec', :version => 2 do
2
+ watch(%r{^spec/.+_spec\.rb$})
3
+ watch(%r{^lib/(.+)\.rb$}) { |m| "spec/#{m[1]}_spec.rb" }
4
+ watch('spec/spec_helper.rb') { "spec" }
5
+ end
6
+
7
+
8
+ guard 'bundler' do
9
+ watch('Gemfile')
10
+ watch(/^.+\.gemspec/)
11
+ end
data/README.md ADDED
@@ -0,0 +1,48 @@
1
+ # OmniAuth Canvas
2
+ Gem to authenticate with Instructure Canvas via OAuth2
3
+
4
+ # Background
5
+ OmniAuth Canvas grew out of the need to simplify the process of setting up LTI and connecting a user account on
6
+ http://www.OpenTapestry.com to Instructure Canvas.
7
+
8
+ # Setup
9
+ Contact Instructure or your Canvas administrator to get an OAuth key and secret. By default omniauth-canvas will attempt to
10
+ authenticate with http://canvas.instructure.com. To dynamically set the canvas site url do the following:
11
+
12
+ ## Standard setup:
13
+
14
+ use OmniAuth::Builder do
15
+ provider :canvas, :setup => lambda{|env|
16
+ request = Rack::Request.new(env)
17
+ env['omniauth.strategy'].options[:client_options].site = env['rack.session']['oauth_site']
18
+ }
19
+ end
20
+
21
+ ## Setup with Devise:
22
+
23
+ config.omniauth :canvas, 'canvas_key', 'canvas_secret', :setup => lambda{|env|
24
+ request = Rack::Request.new(env)
25
+ env['omniauth.strategy'].options[:client_options].site = env['rack.session']['oauth_site']
26
+ }
27
+
28
+ ## License
29
+
30
+ Copyright (C) 2012 by Justin Ball and Open Tapestry, Inc.
31
+
32
+ Permission is hereby granted, free of charge, to any person obtaining a copy
33
+ of this software and associated documentation files (the "Software"), to deal
34
+ in the Software without restriction, including without limitation the rights
35
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
36
+ copies of the Software, and to permit persons to whom the Software is
37
+ furnished to do so, subject to the following conditions:
38
+
39
+ The above copyright notice and this permission notice shall be included in
40
+ all copies or substantial portions of the Software.
41
+
42
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
43
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
44
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
45
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
46
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
47
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
48
+ THE SOFTWARE.
data/Rakefile ADDED
@@ -0,0 +1,16 @@
1
+ #!/usr/bin/env rake
2
+ $: << File.dirname(__FILE__)
3
+
4
+ require 'bundler'
5
+ require 'rake'
6
+ require 'rspec/core/rake_task'
7
+
8
+ Bundler::GemHelper.install_tasks
9
+
10
+ task :default => [:spec]
11
+ task :test => [:spec]
12
+
13
+ desc "run spec tests"
14
+ RSpec::Core::RakeTask.new('spec') do |t|
15
+ t.pattern = 'spec/**/*_spec.rb'
16
+ end
@@ -0,0 +1,45 @@
1
+ require "omniauth-oauth2"
2
+
3
+ module OmniAuth
4
+ module Strategies
5
+ class Canvas < OmniAuth::Strategies::OAuth2
6
+
7
+ option :name, "Canvas"
8
+
9
+ option :client_options, {
10
+ :site => "https://canvas.instructure.com",
11
+ :authorize_url => "/login/oauth2/auth",
12
+ :token_url => "/login/oauth2/token"
13
+ }
14
+ option :token_params, {
15
+ :parse => :json
16
+ }
17
+
18
+ uid do
19
+ access_token['user']['id']
20
+ end
21
+
22
+ info do
23
+ {
24
+ 'name' => raw_info['name'],
25
+ 'email' => raw_info['primary_email'],
26
+ 'bio' => raw_info['bio'],
27
+ 'title' => raw_info['title'],
28
+ 'nickname' => raw_info['login_id'],
29
+ 'active_avatar' => raw_info['avatar_url'],
30
+ 'token' => access_token.token,
31
+ }
32
+ end
33
+
34
+ extra do
35
+ { :raw_info => raw_info }
36
+ end
37
+
38
+ def raw_info
39
+ @raw_info ||= access_token.get("/api/v1/users/#{access_token['user']['id']}/profile").parsed
40
+ end
41
+
42
+ end
43
+ end
44
+ end
45
+ OmniAuth.config.add_camelization 'canvas', 'Canvas'
@@ -0,0 +1,5 @@
1
+ module OmniAuth
2
+ module Canvas
3
+ VERSION = "0.0.1"
4
+ end
5
+ end
@@ -0,0 +1,2 @@
1
+ require "omniauth-canvas/version"
2
+ require 'omniauth/strategies/canvas'
@@ -0,0 +1,20 @@
1
+ # -*- encoding: utf-8 -*-
2
+ require File.expand_path('../lib/omniauth-canvas/version', __FILE__)
3
+
4
+ Gem::Specification.new do |gem|
5
+ gem.authors = "Justin Ball"
6
+ gem.email = "justin@opentapestry.com"
7
+ gem.description = %q{OmniAuth Oauth2 strategy for Instructure Canvas.}
8
+ gem.summary = %q{OmniAuth Oauth2 strategy for Instructure Canvas.}
9
+ gem.homepage = "https://github.com/tatemae/omniauth-canvas"
10
+
11
+ gem.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
12
+ gem.files = `git ls-files`.split("\n")
13
+ gem.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
14
+ gem.name = "omniauth-canvas"
15
+ gem.require_paths = ["lib"]
16
+ gem.version = OmniAuth::Canvas::VERSION
17
+
18
+ gem.add_dependency 'omniauth', '~> 1.0'
19
+ gem.add_dependency 'omniauth-oauth2', '~> 1.0'
20
+ end
@@ -0,0 +1,36 @@
1
+ require 'spec_helper'
2
+
3
+ describe OmniAuth::Strategies::OAuth2 do
4
+ def app; lambda{|env| [200, {}, ["Hello."]]} end
5
+
6
+ before do
7
+ @request = double('Request')
8
+ @request.stub(:params) { {} }
9
+ OmniAuth.config.test_mode = true
10
+ end
11
+
12
+ subject do
13
+ OmniAuth::Strategies::Canvas.new(nil, @options || {}).tap do |strategy|
14
+ strategy.stub(:request) { @request }
15
+ end
16
+ end
17
+
18
+ after do
19
+ OmniAuth.config.test_mode = false
20
+ end
21
+
22
+ context "client options" do
23
+ it "has correct api site" do
24
+ subject.options.client_options.site.should eq("https://canvas.instructure.com")
25
+ end
26
+
27
+ it "has correct access token path" do
28
+ subject.options.client_options.token_url.should eq("/login/oauth2/token")
29
+ end
30
+
31
+ it "has correct authorize url" do
32
+ subject.options.client_options.authorize_url.should eq("/login/oauth2/auth")
33
+ end
34
+ end
35
+
36
+ end
@@ -0,0 +1,14 @@
1
+ $:.unshift File.expand_path('..', __FILE__)
2
+ $:.unshift File.expand_path('../../lib', __FILE__)
3
+ require 'simplecov'
4
+ SimpleCov.start
5
+ require 'rspec'
6
+ require 'rack/test'
7
+ require 'omniauth'
8
+ require 'omniauth-canvas'
9
+
10
+ RSpec.configure do |config|
11
+ config.include Rack::Test::Methods
12
+ config.extend OmniAuth::Test::StrategyMacros, :type => :strategy
13
+ end
14
+
metadata ADDED
@@ -0,0 +1,91 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: omniauth-canvas
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Justin Ball
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-09-14 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: omniauth
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ~>
20
+ - !ruby/object:Gem::Version
21
+ version: '1.0'
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ~>
28
+ - !ruby/object:Gem::Version
29
+ version: '1.0'
30
+ - !ruby/object:Gem::Dependency
31
+ name: omniauth-oauth2
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ~>
36
+ - !ruby/object:Gem::Version
37
+ version: '1.0'
38
+ type: :runtime
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ~>
44
+ - !ruby/object:Gem::Version
45
+ version: '1.0'
46
+ description: OmniAuth Oauth2 strategy for Instructure Canvas.
47
+ email: justin@opentapestry.com
48
+ executables: []
49
+ extensions: []
50
+ extra_rdoc_files: []
51
+ files:
52
+ - .gitignore
53
+ - .rspec
54
+ - .rvmrc
55
+ - Gemfile
56
+ - Guardfile
57
+ - README.md
58
+ - Rakefile
59
+ - lib/omniauth-canvas.rb
60
+ - lib/omniauth-canvas/version.rb
61
+ - lib/omniauth/strategies/canvas.rb
62
+ - omniauth-canvas.gemspec
63
+ - spec/omniauth/strategies/canvas_spec.rb
64
+ - spec/spec_helper.rb
65
+ homepage: https://github.com/tatemae/omniauth-canvas
66
+ licenses: []
67
+ post_install_message:
68
+ rdoc_options: []
69
+ require_paths:
70
+ - lib
71
+ required_ruby_version: !ruby/object:Gem::Requirement
72
+ none: false
73
+ requirements:
74
+ - - ! '>='
75
+ - !ruby/object:Gem::Version
76
+ version: '0'
77
+ required_rubygems_version: !ruby/object:Gem::Requirement
78
+ none: false
79
+ requirements:
80
+ - - ! '>='
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ requirements: []
84
+ rubyforge_project:
85
+ rubygems_version: 1.8.24
86
+ signing_key:
87
+ specification_version: 3
88
+ summary: OmniAuth Oauth2 strategy for Instructure Canvas.
89
+ test_files:
90
+ - spec/omniauth/strategies/canvas_spec.rb
91
+ - spec/spec_helper.rb