Skip to content

Commit

Permalink
initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
rivernate committed Oct 15, 2014
0 parents commit 69622c0
Show file tree
Hide file tree
Showing 82 changed files with 1,404 additions and 0 deletions.
8 changes: 8 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
.bundle/
log/*.log
pkg/
spec/test_app/db/*.sqlite3
spec/test_app/db/*.sqlite3-journal
spec/test_app/log/*.log
spec/test_app/tmp/
spec/test_app/.sass-cache
3 changes: 3 additions & 0 deletions .rspec
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
--color
--warnings
--require spec_helper
14 changes: 14 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
source "https://rubygems.org"

# Declare your gem's dependencies in rails_lti2_provider.gemspec.
# Bundler will treat runtime dependencies like base dependencies, and
# development dependencies will be added by default to the :development group.
gemspec

# Declare any dependencies that are still in development here instead of in
# your gemspec. These might include edge Rails or gems from your path or
# Git. Remember to move these dependencies to your gemspec before releasing
# your gem to rubygems.org.

# To use debugger
# gem 'debugger'
116 changes: 116 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
PATH
remote: .
specs:
rails_lti2_provider (0.0.1)
ims-lti (~> 2.0.0.beta.11)
rails (~> 4.1.6)

GEM
remote: https://rubygems.org/
specs:
actionmailer (4.1.6)
actionpack (= 4.1.6)
actionview (= 4.1.6)
mail (~> 2.5, >= 2.5.4)
actionpack (4.1.6)
actionview (= 4.1.6)
activesupport (= 4.1.6)
rack (~> 1.5.2)
rack-test (~> 0.6.2)
actionview (4.1.6)
activesupport (= 4.1.6)
builder (~> 3.1)
erubis (~> 2.7.0)
activemodel (4.1.6)
activesupport (= 4.1.6)
builder (~> 3.1)
activerecord (4.1.6)
activemodel (= 4.1.6)
activesupport (= 4.1.6)
arel (~> 5.0.0)
activesupport (4.1.6)
i18n (~> 0.6, >= 0.6.9)
json (~> 1.7, >= 1.7.7)
minitest (~> 5.1)
thread_safe (~> 0.1)
tzinfo (~> 1.1)
arel (5.0.1.20140414130214)
builder (3.2.2)
diff-lcs (1.2.5)
erubis (2.7.0)
faraday (0.9.0)
multipart-post (>= 1.2, < 3)
faraday_middleware (0.9.1)
faraday (>= 0.7.4, < 0.10)
hike (1.2.3)
i18n (0.6.11)
ims-lti (2.0.0.beta.11)
faraday (~> 0.8)
faraday_middleware (~> 0.8)
simple_oauth (= 0.2)
json (1.8.1)
mail (2.6.1)
mime-types (>= 1.16, < 3)
mime-types (2.4.2)
minitest (5.4.2)
multi_json (1.10.1)
multipart-post (2.0.0)
rack (1.5.2)
rack-test (0.6.2)
rack (>= 1.0)
rails (4.1.6)
actionmailer (= 4.1.6)
actionpack (= 4.1.6)
actionview (= 4.1.6)
activemodel (= 4.1.6)
activerecord (= 4.1.6)
activesupport (= 4.1.6)
bundler (>= 1.3.0, < 2.0)
railties (= 4.1.6)
sprockets-rails (~> 2.0)
railties (4.1.6)
actionpack (= 4.1.6)
activesupport (= 4.1.6)
rake (>= 0.8.7)
thor (>= 0.18.1, < 2.0)
rake (10.3.2)
rspec-core (3.0.4)
rspec-support (~> 3.0.0)
rspec-expectations (3.0.4)
diff-lcs (>= 1.2.0, < 2.0)
rspec-support (~> 3.0.0)
rspec-mocks (3.0.4)
rspec-support (~> 3.0.0)
rspec-rails (3.0.2)
actionpack (>= 3.0)
activesupport (>= 3.0)
railties (>= 3.0)
rspec-core (~> 3.0.0)
rspec-expectations (~> 3.0.0)
rspec-mocks (~> 3.0.0)
rspec-support (~> 3.0.0)
rspec-support (3.0.4)
simple_oauth (0.2.0)
sprockets (2.12.2)
hike (~> 1.2)
multi_json (~> 1.0)
rack (~> 1.0)
tilt (~> 1.1, != 1.3.0)
sprockets-rails (2.2.0)
actionpack (>= 3.0)
activesupport (>= 3.0)
sprockets (>= 2.8, < 4.0)
sqlite3 (1.3.9)
thor (0.19.1)
thread_safe (0.3.4)
tilt (1.4.1)
tzinfo (1.2.2)
thread_safe (~> 0.1)

PLATFORMS
ruby

DEPENDENCIES
rails_lti2_provider!
rspec-rails
sqlite3
20 changes: 20 additions & 0 deletions MIT-LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
Copyright 2014 YOURNAME

Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:

The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
3 changes: 3 additions & 0 deletions README.rdoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
= RailsLti2Provider

This project rocks and uses MIT-LICENSE.
23 changes: 23 additions & 0 deletions Rakefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
begin
require 'bundler/setup'
rescue LoadError
puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
end

require 'rdoc/task'

RDoc::Task.new(:rdoc) do |rdoc|
rdoc.rdoc_dir = 'rdoc'
rdoc.title = 'RailsLti2Provider'
rdoc.options << '--line-numbers'
rdoc.rdoc_files.include('README.rdoc')
rdoc.rdoc_files.include('lib/**/*.rb')
end

APP_RAKEFILE = File.expand_path("../spec/test_app/Rakefile", __FILE__)
load 'rails/tasks/engine.rake'



Bundler::GemHelper.install_tasks

Empty file.
13 changes: 13 additions & 0 deletions app/assets/javascripts/rails_lti2_provider/application.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
// This is a manifest file that'll be compiled into application.js, which will include all the files
// listed below.
//
// Any JavaScript/Coffee file within this directory, lib/assets/javascripts, vendor/assets/javascripts,
// or vendor/assets/javascripts of plugins, if any, can be referenced here using a relative path.
//
// It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the
// compiled file.
//
// Read Sprockets README (https://github.com/sstephenson/sprockets#sprockets-directives) for details
// about supported directives.
//
//= require_tree .
2 changes: 2 additions & 0 deletions app/assets/javascripts/rails_lti2_provider/tool_proxy.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
// Place all the behaviors and hooks related to the matching controller here.
// All this logic will automatically be available in application.js.
15 changes: 15 additions & 0 deletions app/assets/stylesheets/rails_lti2_provider/application.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
/*
* This is a manifest file that'll be compiled into application.css, which will include all the files
* listed below.
*
* Any CSS and SCSS file within this directory, lib/assets/stylesheets, vendor/assets/stylesheets,
* or vendor/assets/stylesheets of plugins, if any, can be referenced here using a relative path.
*
* You're free to add application-wide styles to this file and they'll appear at the bottom of the
* compiled file so the styles you add here take precedence over styles defined in any styles
* defined in the other CSS/SCSS files in this directory. It is generally better to create a new
* file per style scope.
*
*= require_tree .
*= require_self
*/
4 changes: 4 additions & 0 deletions app/assets/stylesheets/rails_lti2_provider/tool_proxy.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
/*
Place all the styles related to the matching controller here.
They will automatically be included in application.css.
*/
4 changes: 4 additions & 0 deletions app/controllers/rails_lti2_provider/application_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
module RailsLti2Provider
class ApplicationController < ActionController::Base
end
end
5 changes: 5 additions & 0 deletions app/controllers/rails_lti2_provider/tool_proxy_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
module RailsLti2Provider
class ToolProxyController < ApplicationController
include RailsLti2Provider::Concerns::Controllers::ToolProxyController
end
end
4 changes: 4 additions & 0 deletions app/helpers/rails_lti2_provider/application_helper.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
module RailsLti2Provider
module ApplicationHelper
end
end
4 changes: 4 additions & 0 deletions app/helpers/rails_lti2_provider/tool_proxy_helper.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
module RailsLti2Provider
module ToolProxyHelper
end
end
23 changes: 23 additions & 0 deletions app/models/rails_lti2_provider/lti_launch.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
module RailsLti2Provider
class LtiLaunch < ActiveRecord::Base
validates_presence_of :tool_proxy_id, :nonce
has_one :tool_proxy
serialize :message

def self.check_launch(lti_message)
tool_proxy = ToolProxy.find_by_uuid(lti_message.oauth_consumer_key)
valid_launch = lti_message.valid_signature?(tool_proxy.shared_secret) &&
tool_proxy.lti_launches.where(nonce: lti_message.oauth_nonce).count == 0 &&
DateTime.strptime(lti_message.oauth_timestamp,'%s') > 5.minutes.ago
raise Unauthorized unless valid_launch
tool_proxy.lti_launches.where('created_at > ?', 1.day.ago).delete_all
tool_proxy.lti_launches.create(nonce: lti_message.oauth_nonce, message: lti_message.post_params)
lti_message
end

class Unauthorized < StandardError;
end


end
end
7 changes: 7 additions & 0 deletions app/models/rails_lti2_provider/tool_proxy.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
module RailsLti2Provider
class ToolProxy < ActiveRecord::Base
validates_presence_of :shared_secret, :uuid, :proxy_json
serialize :proxy_json, JSON
has_many :lti_launches
end
end
14 changes: 14 additions & 0 deletions app/views/layouts/rails_lti2_provider/application.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<!DOCTYPE html>
<html>
<head>
<title>RailsLti2Provider</title>
<%= stylesheet_link_tag "rails_lti2_provider/application", media: "all" %>
<%= javascript_include_tag "rails_lti2_provider/application" %>
<%= csrf_meta_tags %>
</head>
<body>

<%= yield %>

</body>
</html>
2 changes: 2 additions & 0 deletions app/views/rails_lti2_provider/tool_proxy/register.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
<h1>ToolProxy#register</h1>
<p>Find me in app/views/rails_lti2_provider/tool_proxy/register.html.erb</p>
12 changes: 12 additions & 0 deletions bin/rails
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#!/usr/bin/env ruby
# This command will automatically be run when you run "rails" with Rails 4 gems installed from the root of your application.

ENGINE_ROOT = File.expand_path('../..', __FILE__)
ENGINE_PATH = File.expand_path('../../lib/rails_lti2_provider/engine', __FILE__)

# Set up gems listed in the Gemfile.
ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../Gemfile', __FILE__)
require 'bundler/setup' if File.exist?(ENV['BUNDLE_GEMFILE'])

require 'rails/all'
require 'rails/engine/commands'
16 changes: 16 additions & 0 deletions bin/rspec
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#!/usr/bin/env ruby
#
# This file was generated by Bundler.
#
# The application 'rspec' is installed as part of a gem, and
# this file is here to facilitate running it.
#

require 'pathname'
ENV['BUNDLE_GEMFILE'] ||= File.expand_path("../../Gemfile",
Pathname.new(__FILE__).realpath)

require 'rubygems'
require 'bundler/setup'

load Gem.bin_path('rspec-core', 'rspec')
18 changes: 18 additions & 0 deletions config/routes.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
RailsLti2Provider::Engine.routes.draw do

Rails.application.routes.draw do
RailsLti2Provider::RESOURCE_HANDLERS.each do |config|
config[:messages].each do |message|
route = message[:route].symbolize_keys
path = route.delete(:path) || ':controller/:action'
post path, route
end
end
end

post 'tool_proxy/register', to: 'tool_proxy#register', as: :tool_proxy_registrar

get 'tool_proxy/:tool_proxy_id', to: 'tool_proxy#show', as: :show_tool_proxy


end
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
class CreateRailsLti2ProviderToolProxies < ActiveRecord::Migration
def change
create_table :rails_lti2_provider_tool_proxies do |t|
t.string :uuid
t.string :shared_secret
t.text :proxy_json

t.timestamps
end
end
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
class CreateRailsLti2ProviderLtiLaunches < ActiveRecord::Migration
def change
create_table :rails_lti2_provider_lti_launches do |t|
t.string :tool_proxy_id
t.string :nonce
t.text :message

t.timestamps
end
end
end
9 changes: 9 additions & 0 deletions lib/rails_lti2_provider.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
require "ims/lti"

module RailsLti2Provider
require "rails_lti2_provider/engine"
require "rails_lti2_provider/concerns"
require "rails_lti2_provider/tool_proxy_registration"
require "rails_lti2_provider/controller_helpers"

end
3 changes: 3 additions & 0 deletions lib/rails_lti2_provider/concerns.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module RailsLti2Provider::Concerns
require_relative 'concerns/controllers'
end
3 changes: 3 additions & 0 deletions lib/rails_lti2_provider/concerns/controllers.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module RailsLti2Provider::Concerns::Controllers
require_relative "controllers/tool_proxy_controller"
end
Loading

0 comments on commit 69622c0

Please sign in to comment.