omniauth-lti 0.0.1
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.
- data/.gitignore +4 -0
- data/Gemfile +4 -0
- data/README.md +40 -0
- data/Rakefile +1 -0
- data/lib/omniauth/lti.rb +9 -0
- data/lib/omniauth/strategies/lti.rb +58 -0
- data/lib/omniauth-lti/context.rb +42 -0
- data/lib/omniauth-lti/version.rb +5 -0
- data/lib/omniauth-lti.rb +3 -0
- data/omniauth-lti.gemspec +26 -0
- metadata +85 -0
data/.gitignore
ADDED
data/Gemfile
ADDED
data/README.md
ADDED
@@ -0,0 +1,40 @@
|
|
1
|
+
OmniAuth LTI
|
2
|
+
============
|
3
|
+
|
4
|
+
The OmniAuth LTI gem provides a way for applications to authenticate users using LTI 1.1 specification.
|
5
|
+
|
6
|
+
It relies on [ims-lti gem][] for validating LTI data.
|
7
|
+
|
8
|
+
Usage
|
9
|
+
=====
|
10
|
+
|
11
|
+
Add the provider to your OmniAuth stack, giving the tool_consumer credentials:
|
12
|
+
|
13
|
+
Rails.application.config.middleware.use OmniAuth::Builder do
|
14
|
+
provider :lti, :oauth_credentials => {:test => 'secret'}
|
15
|
+
end
|
16
|
+
|
17
|
+
Include Omniauth::Lti::Context in your application_controller:
|
18
|
+
|
19
|
+
class ApplicationController < ActionController::Base
|
20
|
+
...
|
21
|
+
include Omniauth::Lti::Context
|
22
|
+
...
|
23
|
+
end
|
24
|
+
|
25
|
+
When you create the session in your sessions\_controller, call to save_lti_context for saving LTI context through all the application
|
26
|
+
|
27
|
+
For accessing the context anywhere in your application, just call the helper method lti\_tool\_provider.
|
28
|
+
For instance, to show the title of the resource that call your application just put in your haml view:
|
29
|
+
|
30
|
+
=lti_tool_provider.resource_link_title
|
31
|
+
|
32
|
+
You can find an example web application in [omniauth-lti-example-webapp][]
|
33
|
+
|
34
|
+
TODO
|
35
|
+
=====
|
36
|
+
|
37
|
+
Add support for outcomes
|
38
|
+
|
39
|
+
[ims-lti gem]: https://github.com/instructure/ims-lti
|
40
|
+
[omniauth-lti-example-webapp]: https://github.com/xaviaracil/omniauth-lti-example
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
data/lib/omniauth/lti.rb
ADDED
@@ -0,0 +1,58 @@
|
|
1
|
+
module OmniAuth
|
2
|
+
module Strategies
|
3
|
+
class Lti
|
4
|
+
include OmniAuth::Strategy
|
5
|
+
|
6
|
+
# Hash for storing your Consumer Tools credentials, whether:
|
7
|
+
# - the key is the consumer_key
|
8
|
+
# - the value is the comsumer_secret
|
9
|
+
option :oauth_credentials, {}
|
10
|
+
|
11
|
+
# Defaul username for users when LTI context doesn't provide a name
|
12
|
+
option :default_user_name, 'User'
|
13
|
+
|
14
|
+
def callback_phase
|
15
|
+
# validate request
|
16
|
+
return fail!(:invalid_credentials) unless valid_lti?
|
17
|
+
#save the launch parameters for use in later request
|
18
|
+
env['lti.launch_params'] = @tp.to_params
|
19
|
+
super
|
20
|
+
end
|
21
|
+
|
22
|
+
# define the UID
|
23
|
+
uid { @tp.user_id }
|
24
|
+
|
25
|
+
# define the hash of info about user
|
26
|
+
info do
|
27
|
+
{
|
28
|
+
:name => @tp.username(options.default_user_name),
|
29
|
+
:email => @tp.lis_person_contact_email_primary,
|
30
|
+
:first_name => @tp.lis_person_name_given,
|
31
|
+
:last_name => @tp.lis_person_name_family,
|
32
|
+
:image => @tp.user_image
|
33
|
+
}
|
34
|
+
end
|
35
|
+
|
36
|
+
# define the hash of credentials
|
37
|
+
credentials do
|
38
|
+
{
|
39
|
+
:token => @tp.consumer_key,
|
40
|
+
:secret => @tp.consumer_secret
|
41
|
+
}
|
42
|
+
end
|
43
|
+
|
44
|
+
#define extra hash
|
45
|
+
extra do
|
46
|
+
{ :raw_info => @tp.to_params }
|
47
|
+
end
|
48
|
+
|
49
|
+
private
|
50
|
+
|
51
|
+
def valid_lti?
|
52
|
+
key = request.params['oauth_consumer_key']
|
53
|
+
@tp = IMS::LTI::ToolProvider.new(key, options.oauth_credentials[key], request.params)
|
54
|
+
@tp.valid_request!(request)
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
@@ -0,0 +1,42 @@
|
|
1
|
+
module Omniauth
|
2
|
+
module Lti
|
3
|
+
module Context
|
4
|
+
|
5
|
+
def self.included(receiver)
|
6
|
+
receiver.class_eval do
|
7
|
+
# add lti_tool_provider as a helper method to received object
|
8
|
+
helper_method :lti_tool_provider
|
9
|
+
attr_reader :lti_credentials
|
10
|
+
|
11
|
+
def lti_credentials=(credentials)
|
12
|
+
if credentials && credentials.is_a?(Hash)
|
13
|
+
@lti_credentials = credentials.keys.inject({}) {|h,k| h[k.to_s] = credentials[k] ; h }
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
def save_lti_context
|
20
|
+
session[LTI_LAUNCH_PARAMS_SESSION_NAME] = request.env['lti.launch_params']
|
21
|
+
end
|
22
|
+
|
23
|
+
private
|
24
|
+
|
25
|
+
LTI_LAUNCH_PARAMS_SESSION_NAME = 'lti_launch_params'
|
26
|
+
|
27
|
+
def lti_launch_params
|
28
|
+
session[LTI_LAUNCH_PARAMS_SESSION_NAME]
|
29
|
+
end
|
30
|
+
|
31
|
+
def lti_tool_provider
|
32
|
+
return nil unless lti_launch_params
|
33
|
+
key = lti_launch_params['oauth_consumer_key']
|
34
|
+
secret = self.lti_credentials[key] if self.lti_credentials
|
35
|
+
@tp ||= IMS::LTI::ToolProvider.new(key,
|
36
|
+
secret,
|
37
|
+
lti_launch_params)
|
38
|
+
end
|
39
|
+
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
data/lib/omniauth-lti.rb
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
$:.push File.expand_path("../lib", __FILE__)
|
3
|
+
require "omniauth-lti/version"
|
4
|
+
|
5
|
+
Gem::Specification.new do |s|
|
6
|
+
s.name = "omniauth-lti"
|
7
|
+
s.version = Omniauth::Lti::VERSION
|
8
|
+
s.authors = ["Xavi Aracil"]
|
9
|
+
s.email = ["xavi@laibeth.com"]
|
10
|
+
s.homepage = "https://github.com/xaviaracil/omniauth-lti"
|
11
|
+
s.summary = %q{OmniAuth strategy for LTI spec}
|
12
|
+
s.description = %q{OmniAuth strategy for providing LTI authentication to an OmniAuth application}
|
13
|
+
|
14
|
+
s.rubyforge_project = "omniauth-lti"
|
15
|
+
|
16
|
+
s.files = `git ls-files`.split("\n")
|
17
|
+
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
18
|
+
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
19
|
+
s.require_paths = ["lib"]
|
20
|
+
|
21
|
+
# specify any dependencies here; for example:
|
22
|
+
# s.add_development_dependency "rspec"
|
23
|
+
# s.add_runtime_dependency "rest-client"
|
24
|
+
s.add_dependency 'omniauth'
|
25
|
+
s.add_dependency 'ims-lti'
|
26
|
+
end
|
metadata
ADDED
@@ -0,0 +1,85 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: omniauth-lti
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
prerelease:
|
5
|
+
version: 0.0.1
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Xavi Aracil
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
|
13
|
+
date: 2013-06-03 00:00:00 Z
|
14
|
+
dependencies:
|
15
|
+
- !ruby/object:Gem::Dependency
|
16
|
+
name: omniauth
|
17
|
+
prerelease: false
|
18
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
19
|
+
none: false
|
20
|
+
requirements:
|
21
|
+
- - ">="
|
22
|
+
- !ruby/object:Gem::Version
|
23
|
+
version: "0"
|
24
|
+
type: :runtime
|
25
|
+
version_requirements: *id001
|
26
|
+
- !ruby/object:Gem::Dependency
|
27
|
+
name: ims-lti
|
28
|
+
prerelease: false
|
29
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
30
|
+
none: false
|
31
|
+
requirements:
|
32
|
+
- - ">="
|
33
|
+
- !ruby/object:Gem::Version
|
34
|
+
version: "0"
|
35
|
+
type: :runtime
|
36
|
+
version_requirements: *id002
|
37
|
+
description: OmniAuth strategy for providing LTI authentication to an OmniAuth application
|
38
|
+
email:
|
39
|
+
- xavi@laibeth.com
|
40
|
+
executables: []
|
41
|
+
|
42
|
+
extensions: []
|
43
|
+
|
44
|
+
extra_rdoc_files: []
|
45
|
+
|
46
|
+
files:
|
47
|
+
- .gitignore
|
48
|
+
- Gemfile
|
49
|
+
- README.md
|
50
|
+
- Rakefile
|
51
|
+
- lib/omniauth-lti.rb
|
52
|
+
- lib/omniauth-lti/context.rb
|
53
|
+
- lib/omniauth-lti/version.rb
|
54
|
+
- lib/omniauth/lti.rb
|
55
|
+
- lib/omniauth/strategies/lti.rb
|
56
|
+
- omniauth-lti.gemspec
|
57
|
+
homepage: https://github.com/xaviaracil/omniauth-lti
|
58
|
+
licenses: []
|
59
|
+
|
60
|
+
post_install_message:
|
61
|
+
rdoc_options: []
|
62
|
+
|
63
|
+
require_paths:
|
64
|
+
- lib
|
65
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
66
|
+
none: false
|
67
|
+
requirements:
|
68
|
+
- - ">="
|
69
|
+
- !ruby/object:Gem::Version
|
70
|
+
version: "0"
|
71
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
72
|
+
none: false
|
73
|
+
requirements:
|
74
|
+
- - ">="
|
75
|
+
- !ruby/object:Gem::Version
|
76
|
+
version: "0"
|
77
|
+
requirements: []
|
78
|
+
|
79
|
+
rubyforge_project: omniauth-lti
|
80
|
+
rubygems_version: 1.8.24
|
81
|
+
signing_key:
|
82
|
+
specification_version: 3
|
83
|
+
summary: OmniAuth strategy for LTI spec
|
84
|
+
test_files: []
|
85
|
+
|