Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Remove support for Rails 2.x.x

  • Loading branch information...
commit e9e7e7740c5c5c3fe13aa116ca667410a0fc74e5 1 parent 0afc30e
@pelle authored
Showing with 25 additions and 2,176 deletions.
  1. +2 −0  CHANGELOG
  2. +4 −4 Gemfile
  3. +2 −1  Guardfile
  4. +0 −10 generators/oauth_consumer/USAGE
  5. +0 −50 generators/oauth_consumer/oauth_consumer_generator.rb
  6. +0 −11 generators/oauth_consumer/templates/consumer_token.rb
  7. +0 −27 generators/oauth_consumer/templates/controller.rb
  8. +0 −29 generators/oauth_consumer/templates/index.html.erb
  9. +0 −18 generators/oauth_consumer/templates/index.html.haml
  10. +0 −20 generators/oauth_consumer/templates/migration.rb
  11. +0 −73 generators/oauth_consumer/templates/oauth_config.rb
  12. +0 −7 generators/oauth_consumer/templates/show.html.erb
  13. +0 −8 generators/oauth_consumer/templates/show.html.haml
  14. +0 −20 generators/oauth_provider/USAGE
  15. +0 −67 generators/oauth_provider/lib/insert_routes.rb
  16. +0 −127 generators/oauth_provider/oauth_provider_generator.rb
  17. +0 −17 generators/oauth_provider/templates/_form.html.erb
  18. +0 −21 generators/oauth_provider/templates/_form.html.haml
  19. +0 −16 generators/oauth_provider/templates/access_token.rb
  20. +0 −14 generators/oauth_provider/templates/authorize.html.erb
  21. +0 −16 generators/oauth_provider/templates/authorize.html.haml
  22. +0 −1  generators/oauth_provider/templates/authorize_failure.html.erb
  23. +0 −1  generators/oauth_provider/templates/authorize_failure.html.haml
  24. +0 −1  generators/oauth_provider/templates/authorize_success.html.erb
  25. +0 −1  generators/oauth_provider/templates/authorize_success.html.haml
  26. +0 −57 generators/oauth_provider/templates/client_application.rb
  27. +0 −29 generators/oauth_provider/templates/client_application_spec.rb
  28. +0 −42 generators/oauth_provider/templates/client_application_test.rb
  29. +0 −23 generators/oauth_provider/templates/client_applications.yml
  30. +0 −52 generators/oauth_provider/templates/clients_controller.rb
  31. +0 −176 generators/oauth_provider/templates/clients_controller_spec.rb
  32. +0 −280 generators/oauth_provider/templates/clients_controller_test.rb
  33. +0 −23 generators/oauth_provider/templates/controller.rb
  34. +0 −7 generators/oauth_provider/templates/edit.html.erb
  35. +0 −4 generators/oauth_provider/templates/edit.html.haml
  36. +0 −43 generators/oauth_provider/templates/index.html.erb
  37. +0 −39 generators/oauth_provider/templates/index.html.haml
  38. +0 −47 generators/oauth_provider/templates/migration.rb
  39. +0 −5 generators/oauth_provider/templates/new.html.erb
  40. +0 −5 generators/oauth_provider/templates/new.html.haml
  41. +0 −16 generators/oauth_provider/templates/oauth2_authorize.html.erb
  42. +0 −17 generators/oauth_provider/templates/oauth2_authorize.html.haml
  43. +0 −20 generators/oauth_provider/templates/oauth2_token.rb
  44. +0 −52 generators/oauth_provider/templates/oauth2_token_spec.rb
  45. +0 −35 generators/oauth_provider/templates/oauth2_verifier.rb
  46. +0 −44 generators/oauth_provider/templates/oauth2_verifier_spec.rb
  47. +0 −13 generators/oauth_provider/templates/oauth_nonce.rb
  48. +0 −24 generators/oauth_provider/templates/oauth_nonce_spec.rb
  49. +0 −26 generators/oauth_provider/templates/oauth_nonce_test.rb
  50. +0 −13 generators/oauth_provider/templates/oauth_nonces.yml
  51. +0 −30 generators/oauth_provider/templates/oauth_token.rb
  52. +0 −309 generators/oauth_provider/templates/oauth_token_spec.rb
  53. +0 −57 generators/oauth_provider/templates/oauth_token_test.rb
  54. +0 −17 generators/oauth_provider/templates/oauth_tokens.yml
  55. +0 −40 generators/oauth_provider/templates/request_token.rb
  56. +0 −27 generators/oauth_provider/templates/show.html.erb
  57. +0 −30 generators/oauth_provider/templates/show.html.haml
  58. +16 −13 lib/oauth-provider.rb
  59. +1 −0  oauth-provider.gemspec
  60. +0 −1  rails/init.rb
View
2  CHANGELOG
@@ -1,3 +1,5 @@
+0.5.0-rc2
+ - Remove support for Rails 2.x.x
0.5.0-rc1
- First step at seperating consumer and provider. This branch contains provider
0.4.1
View
8 Gemfile
@@ -6,21 +6,21 @@ gemspec
require 'rbconfig'
platforms :ruby do
- if Config::CONFIG['target_os'] =~ /darwin/i
+ if RbConfig::CONFIG['target_os'] =~ /darwin/i
gem 'rb-fsevent'
gem 'growl'
end
- if Config::CONFIG['target_os'] =~ /linux/i
+ if RbConfig::CONFIG['target_os'] =~ /linux/i
gem 'rb-inotify', '>= 0.5.1'
gem 'libnotify', '~> 0.1.3'
end
end
platforms :jruby do
- if Config::CONFIG['target_os'] =~ /darwin/i
+ if RbConfig::CONFIG['target_os'] =~ /darwin/i
gem 'growl'
end
- if Config::CONFIG['target_os'] =~ /linux/i
+ if RbConfig::CONFIG['target_os'] =~ /linux/i
gem 'rb-inotify', '>= 0.5.1'
gem 'libnotify', '~> 0.1.3'
end
View
3  Guardfile
@@ -1,8 +1,9 @@
# A sample Guardfile
# More info at http://github.com/guard/guard#readme
-guard 'rspec', :version => 2, :cli => '-c' do
+guard 'rspec', :version => 2 do
watch(%r{^spec/(.*)_spec.rb})
watch(%r{^lib/oauth/(.+)\.rb}) { |m| "spec/#{m[1]}_spec.rb" }
+ watch('spec/dummy_provider_models.rb') { "spec" }
watch('spec/spec_helper.rb') { "spec" }
end
View
10 generators/oauth_consumer/USAGE
@@ -1,10 +0,0 @@
-./script/generate oauth_consumer
-
-This creates an OAuth Provider controller as well as requisite models.
-
-It requires an authentication framework such as acts_as_authenticated, restful_authentication or restful_open_id_authentication that provides the methods "login_required" and "current_user".
-
-If you generated the migration file (true by default), make sure you run
-rake db:migrate
-
-See README.rdoc for more.
View
50 generators/oauth_consumer/oauth_consumer_generator.rb
@@ -1,50 +0,0 @@
-require File.expand_path(File.dirname(__FILE__) + "/../oauth_provider/lib/insert_routes.rb")
-
-class OauthConsumerGenerator < Rails::Generator::Base
- default_options :skip_migration => false
-
- def manifest
- record do |m|
-
- # Controller, helper, views, and test directories.
- m.directory File.join('app/models')
- m.directory File.join('app/controllers')
- m.directory File.join('app/helpers')
- m.directory File.join('app/views', 'oauth_consumers')
- m.directory File.join('config/initializers')
-
- m.template 'oauth_config.rb',File.join('config/initializers', "oauth_consumers.rb")
- m.template 'consumer_token.rb',File.join('app/models',"consumer_token.rb")
-
- m.template 'controller.rb',File.join('app/controllers',"oauth_consumers_controller.rb")
- m.route_entry "map.resources :oauth_consumers,:member=>{:callback=>:get}"
-
- @template_extension= options[:haml] ? "haml" : "erb"
-
- m.template "show.html.#{@template_extension}", File.join('app/views', 'oauth_consumers', "show.html.#{@template_extension}")
- m.template "index.html.#{@template_extension}", File.join('app/views', 'oauth_consumers', "index.html.#{@template_extension}")
-
- unless options[:skip_migration]
- m.migration_template 'migration.rb', 'db/migrate', :assigns => {
- :migration_name => "CreateOauthConsumerTokens"
- }, :migration_file_name => "create_oauth_consumer_tokens"
- end
- end
- end
-
- protected
- def banner
- "Usage: #{$0} #{spec.name}"
- end
-
- def add_options!(opt)
- opt.separator ''
- opt.separator 'Options:'
- opt.on("--skip-migration",
- "Don't generate a migration file") { |v| options[:skip_migration] = v }
-# opt.on("--test-unit",
-# "Generate the Test::Unit compatible tests instead of RSpec") { |v| options[:test_unit] = v }
- opt.on("--haml",
- "Templates use haml") { |v| options[:haml] = v }
- end
-end
View
11 generators/oauth_consumer/templates/consumer_token.rb
@@ -1,11 +0,0 @@
-require 'oauth/models/consumers/token'
-class ConsumerToken < ActiveRecord::Base
- include Oauth::Models::Consumers::Token
-
- # You can safely remove this callback if you don't allow login from any of your services
- before_create :create_user
-
- # Modify this with class_name etc to match your application
- belongs_to :user
-
-end
View
27 generators/oauth_consumer/templates/controller.rb
@@ -1,27 +0,0 @@
-require 'oauth/controllers/consumer_controller'
-class OauthConsumersController < ApplicationController
- include Oauth::Controllers::ConsumerController
-
- def index
- @consumer_tokens=ConsumerToken.all :conditions => {:user_id => current_user.id}
- @services=OAUTH_CREDENTIALS.keys-@consumer_tokens.collect{|c| c.class.service_name}
- end
-
- def callback
- super
- end
-
- def client
- super
- end
-
- protected
-
- # Change this to decide where you want to redirect user to after callback is finished.
- # params[:id] holds the service name so you could use this to redirect to various parts
- # of your application depending on what service you're connecting to.
- def go_back
- redirect_to root_url
- end
-
-end
View
29 generators/oauth_consumer/templates/index.html.erb
@@ -1,29 +0,0 @@
-<h1>Services</h1>
-
-<%% if @consumer_tokens.empty? %>
- <p>
- You are currently not connected to any external services.
- </p>
-<%% else %>
- <p>
- You are connected to the following services:
- </p>
- <ul>
- <%% @consumer_tokens.each do |token| %>
- <li>
- <%%= link_to token.class.service_name.to_s.humanize, oauth_consumer_path(token.class.service_name) %>
- </li>
- <%% end %>
- </ul>
-<%% end %>
-
-<%% unless @services.empty? %>
-<h3>You can connect to the following services:</h3>
-<ul>
- <%% @services.each do |service| %>
- <li>
- <%%= link_to service.to_s.humanize, oauth_consumer_path(service) %>
- </li>
- <%% end %>
-</ul>
-<%% end %>
View
18 generators/oauth_consumer/templates/index.html.haml
@@ -1,18 +0,0 @@
-%h1 Services
-
--if @consumer_tokens.empty?
- %p
- You are currently not connected to any external services.
--else
- %p You are connected to the following services:
- %ul
- -@consumer_tokens.each do |token|
- %li
- =link_to token.class.service_name.to_s.humanize, oauth_consumer_path(token.class.service_name)
-
--unless @services.empty?
- %h3 You can connect to the following services:
- %ul
- -@services.each do |service|
- %li
- =link_to service.to_s.humanize,oauth_consumer_path(service)
View
20 generators/oauth_consumer/templates/migration.rb
@@ -1,20 +0,0 @@
-class CreateOauthConsumerTokens < ActiveRecord::Migration
- def self.up
-
- create_table :consumer_tokens do |t|
- t.integer :user_id
- t.string :type, :limit => 30
- t.string :token, :limit => 1024 # This has to be huge because of Yahoo's excessively large tokens
- t.string :secret
- t.timestamps
- end
-
- add_index :consumer_tokens, :token, :unique => true, :length => 100
-
- end
-
- def self.down
- drop_table :consumer_tokens
- end
-
-end
View
73 generators/oauth_consumer/templates/oauth_config.rb
@@ -1,73 +0,0 @@
-# edit this file to contain credentials for the OAuth services you support.
-# each entry needs a corresponding token model.
-#
-# eg. :twitter => TwitterToken, :hour_feed => HourFeedToken etc.
-#
-# OAUTH_CREDENTIALS => {
-# :twitter => {
-# :key => "",
-# :secret => "",
-# :client => :twitter_gem, # :twitter_gem or :oauth_gem (defaults to :twitter_gem)
-# :expose => false, # expose client at /oauth_consumers/twitter/client see docs
-# :allow_login => true # Use :allow_login => true to allow user to login to account
-# },
-# :google => {
-# :key => "",
-# :secret => "",
-# :expose => false, # expose client at /oauth_consumers/google/client see docs
-# :scope => "" # see http://code.google.com/apis/gdata/faq.html#AuthScopes
-# },
-# :github => {
-# :key => "",
-# :secret => "",
-# :expose => false, # expose client at /oauth_consumers/twitter/client see docs
-#
-# },
-# :facebook => {
-# :key => "",
-# :secret => "",
-# :oauth_version => 2,
-# :super_class => 'Oauth2Token' # unnecessary if you have an explicit "class FacebookToken < Oauth2Token",
-# :options => {
-# :site => "https://graph.facebook.com"
-# }
-# },
-# :agree2 => {
-# :key => "",
-# :secret => ""
-# },
-# :fireeagle => {
-# :key => "",
-# :secret => ""
-# },
-# :oauth2_server => {
-# :key => "",
-# :secret => "",
-# :oauth_version => 2
-# :options => { # OAuth::Consumer options
-# :site => "http://hourfeed.com" # Remember to add a site for a generic OAuth site
-# }
-# },
-# :hour_feed => {
-# :key => "",
-# :secret => "",
-# :options => { # OAuth::Consumer options
-# :site => "http://hourfeed.com" # Remember to add a site for a generic OAuth site
-# }
-# },
-# :nu_bux => {
-# :key => "",
-# :secret => "",
-# :super_class => "OpenTransactToken", # if a OAuth service follows a particular standard
-# # with a token implementation you can set the superclass
-# # to use
-# :options => { # OAuth::Consumer options
-# :site => "http://nubux.heroku.com"
-# }
-# }
-# }
-#
-OAUTH_CREDENTIALS = {
-} unless defined? OAUTH_CREDENTIALS
-
-load 'oauth/models/consumers/service_loader.rb'
View
7 generators/oauth_consumer/templates/show.html.erb
@@ -1,7 +0,0 @@
-<h1>You are already Connected to <%%=params[:id].humanize%></h1>
-<%% form_tag oauth_consumer_path(params[:id]),:method=>:delete do %>
- <%%=submit_tag "Disconnect" %>
- or
- <%%=submit_tag "Reconnect" %>
- if you experienced a problem.
-<%% end %>
View
8 generators/oauth_consumer/templates/show.html.haml
@@ -1,8 +0,0 @@
-%h1
- You are already Connected to
- =params[:id].humanize
--form_tag oauth_consumer_path(params[:id]),:method=>:delete do
- =submit_tag "Disconnect"
- or
- =submit_tag "Reconnect"
- if you experienced a problem.
View
20 generators/oauth_provider/USAGE
@@ -1,20 +0,0 @@
-./script/generate oauth_provider
-
-This creates an OAuth Provider controller as well as the requisite models.
-
-It requires an authentication framework such as acts_as_authenticated, restful_authentication or restful_open_id_authentication.
-
-If you generated the migration file (true by default), make sure you run
-
- rake db:migrate
-
-include the following in your user.rb
-
- has_many :client_applications
- has_many :tokens, :class_name=>"OauthToken",:order=>"authorized_at desc",:include=>[:client_application]
-
-For legacy OAUTH 1.0 support add the following constant in your environment.rb
-
- OAUTH_10_SUPPORT = true
-
-Note, you should only do this if you really positively require to support old OAuth1.0 clients. There is a serious security issue with this.
View
67 generators/oauth_provider/lib/insert_routes.rb
@@ -1,67 +0,0 @@
-# Stolen from http://github.com/technoweenie/restful-authentication
-
-Rails::Generator::Commands::Create.class_eval do
- def route_entry(raw)
- sentinel = 'ActionController::Routing::Routes.draw do |map|'
-
- logger.route raw
- unless options[:pretend]
- gsub_file 'config/routes.rb', /(#{Regexp.escape(sentinel)})/mi do |match|
- "#{match}\n #{raw}\n"
- end
- end
- end
-
- def route_resource(*resources)
- resource_list = resources.map { |r| r.to_sym.inspect }.join(', ')
- sentinel = 'ActionController::Routing::Routes.draw do |map|'
-
- logger.route "map.resource #{resource_list}"
- unless options[:pretend]
- gsub_file 'config/routes.rb', /(#{Regexp.escape(sentinel)})/mi do |match|
- "#{match}\n map.resource #{resource_list}\n"
- end
- end
- end
-
- def route_name(name, path, route_options = {})
- sentinel = 'ActionController::Routing::Routes.draw do |map|'
-
- logger.route "map.#{name} '#{path}', :controller => '#{route_options[:controller]}', :action => '#{route_options[:action]}'"
- unless options[:pretend]
- gsub_file 'config/routes.rb', /(#{Regexp.escape(sentinel)})/mi do |match|
- "#{match}\n map.#{name} '#{path}', :controller => '#{route_options[:controller]}', :action => '#{route_options[:action]}'"
- end
- end
- end
-end
-
-Rails::Generator::Commands::Destroy.class_eval do
- def route_resource(*resources)
- resource_list = resources.map { |r| r.to_sym.inspect }.join(', ')
- look_for = "\n map.resource #{resource_list}\n"
- logger.route "map.resource #{resource_list}"
- unless options[:pretend]
- gsub_file 'config/routes.rb', /(#{look_for})/mi, ''
- end
- end
-
- def route_name(name, path, route_options = {})
- look_for = "\n map.#{name} '#{path}', :controller => '#{route_options[:controller]}', :action => '#{route_options[:action]}'"
- logger.route "map.#{name} '#{path}', :controller => '#{route_options[:controller]}', :action => '#{route_options[:action]}'"
- unless options[:pretend]
- gsub_file 'config/routes.rb', /(#{look_for})/mi, ''
- end
- end
-end
-
-Rails::Generator::Commands::List.class_eval do
- def route_resource(*resources)
- resource_list = resources.map { |r| r.to_sym.inspect }.join(', ')
- logger.route "map.resource #{resource_list}"
- end
-
- def route_name(name, path, options = {})
- logger.route "map.#{name} '#{path}', :controller => '{options[:controller]}', :action => '#{options[:action]}'"
- end
-end
View
127 generators/oauth_provider/oauth_provider_generator.rb
@@ -1,127 +0,0 @@
-require File.expand_path(File.dirname(__FILE__) + "/lib/insert_routes.rb")
-class OauthProviderGenerator < Rails::Generator::Base
- default_options :skip_migration => false
- attr_reader :class_path,
- :controller_name,
- :controller_class_path,
- :controller_file_path,
- :controller_class_name,
- :controller_singular_name,
- :controller_plural_name
- alias_method :controller_file_name, :controller_singular_name
-
- def initialize(runtime_args, runtime_options = {})
- super
-
- @controller_name = args.shift || 'oauth'
- @controller_singular_name = 'oauth'
- @controller_plural_name = 'oauth'
- @controller_file_name = 'oauth'
- @controller_class_name="Oauth"
- @class_path=''
- @controller_class_path=''
- end
-
- def manifest
- record do |m|
-
- # Check for class naming collisions.
- # Check for class naming collisions.
- m.class_collisions controller_class_path, "#{controller_class_name}Controller", # Oauth Controller
- "#{controller_class_name}Helper",
- "#{controller_class_name}ClientsController",
- "#{controller_class_name}ClientsHelper"
- m.class_collisions class_path, "ClientApplication","OauthNonce","RequestToken","AccessToken","OauthToken"
-
- # Controller, model, views, and test directories.
- m.directory File.join('app/models', class_path)
- m.directory File.join('app/controllers', controller_class_path)
- m.directory File.join('app/views', controller_class_path, controller_file_name)
- m.directory File.join('app/views', controller_class_path, 'oauth_clients')
-
- m.template 'client_application.rb',File.join('app/models',"client_application.rb")
- m.template 'oauth_token.rb', File.join('app/models',"oauth_token.rb")
- m.template 'request_token.rb', File.join('app/models',"request_token.rb")
- m.template 'access_token.rb', File.join('app/models',"access_token.rb")
- m.template 'oauth2_token.rb', File.join('app/models',"oauth2_token.rb")
- m.template 'oauth2_verifier.rb', File.join('app/models',"oauth2_verifier.rb")
- m.template 'oauth_nonce.rb', File.join('app/models',"oauth_nonce.rb")
-
- m.template 'controller.rb',File.join('app/controllers',controller_class_path,"#{controller_file_name}_controller.rb")
-
- m.template 'clients_controller.rb',File.join('app/controllers',controller_class_path,"#{controller_file_name}_clients_controller.rb")
- m.route_name 'oauth', '/oauth',:controller=>'oauth',:action=>'index'
- m.route_name 'authorize', '/oauth/authorize',:controller=>'oauth',:action=>'authorize'
- m.route_name 'request_token', '/oauth/request_token',:controller=>'oauth',:action=>'request_token'
- m.route_name 'access_token', '/oauth/access_token',:controller=>'oauth',:action=>'access_token'
- m.route_name 'token', '/oauth/token',:controller=>'oauth',:action=>'token'
- m.route_name 'test_request', '/oauth/test_request',:controller=>'oauth',:action=>'test_request'
-
- m.route_resources "#{controller_file_name}_clients".to_sym
-
- if !options[:test_unit]
- m.directory File.join('spec')
- m.directory File.join('spec/models')
- m.directory File.join('spec/fixtures', class_path)
- m.directory File.join('spec/controllers', controller_class_path)
-
- m.template 'client_application_spec.rb',File.join('spec/models',"client_application_spec.rb")
- m.template 'oauth_token_spec.rb', File.join('spec/models',"oauth_token_spec.rb")
- m.template 'oauth2_token_spec.rb', File.join('spec/models',"oauth2_token_spec.rb")
- m.template 'oauth2_verifier_spec.rb', File.join('spec/models',"oauth2_verifier_spec.rb")
- m.template 'oauth_nonce_spec.rb', File.join('spec/models',"oauth_nonce_spec.rb")
- m.template 'client_applications.yml',File.join('spec/fixtures',"client_applications.yml")
- m.template 'oauth_tokens.yml', File.join('spec/fixtures',"oauth_tokens.yml")
- m.template 'oauth_nonces.yml', File.join('spec/fixtures',"oauth_nonces.yml")
- m.template 'clients_controller_spec.rb',File.join('spec/controllers',controller_class_path,"#{controller_file_name}_clients_controller_spec.rb")
- else
- m.directory File.join('test')
- m.directory File.join('test/unit')
- m.directory File.join('test/fixtures', class_path)
- m.directory File.join('test/functional', controller_class_path)
- m.template 'client_application_test.rb',File.join('test/unit',"client_application_test.rb")
- m.template 'oauth_token_test.rb', File.join('test/unit',"oauth_token_test.rb")
- m.template 'oauth_nonce_test.rb', File.join('test/unit',"oauth_nonce_test.rb")
- m.template 'client_applications.yml',File.join('test/fixtures',"client_applications.yml")
- m.template 'oauth_tokens.yml', File.join('test/fixtures',"oauth_tokens.yml")
- m.template 'oauth_nonces.yml', File.join('test/fixtures',"oauth_nonces.yml")
- m.template 'clients_controller_test.rb',File.join('test/functional',controller_class_path,"#{controller_file_name}_clients_controller_test.rb")
- end
-
-
- @template_extension= options[:haml] ? "haml" : "erb"
-
- m.template "_form.html.#{@template_extension}", File.join('app/views', controller_class_path, 'oauth_clients', "_form.html.#{@template_extension}")
- m.template "new.html.#{@template_extension}", File.join('app/views', controller_class_path, 'oauth_clients', "new.html.#{@template_extension}")
- m.template "index.html.#{@template_extension}", File.join('app/views', controller_class_path, 'oauth_clients', "index.html.#{@template_extension}")
- m.template "show.html.#{@template_extension}", File.join('app/views', controller_class_path, 'oauth_clients', "show.html.#{@template_extension}")
- m.template "edit.html.#{@template_extension}", File.join('app/views', controller_class_path, 'oauth_clients', "edit.html.#{@template_extension}")
- m.template "authorize.html.#{@template_extension}", File.join('app/views', controller_class_path, controller_file_name, "authorize.html.#{@template_extension}")
- m.template "oauth2_authorize.html.#{@template_extension}", File.join('app/views', controller_class_path, controller_file_name, "oauth2_authorize.html.#{@template_extension}")
- m.template "authorize_success.html.#{@template_extension}", File.join('app/views', controller_class_path, controller_file_name, "authorize_success.html.#{@template_extension}")
- m.template "authorize_failure.html.#{@template_extension}", File.join('app/views', controller_class_path, controller_file_name, "authorize_failure.html.#{@template_extension}")
-
- unless options[:skip_migration]
- m.migration_template 'migration.rb', 'db/migrate', :assigns => {
- :migration_name => "CreateOauthTables"
- }, :migration_file_name => "create_oauth_tables"
- end
- end
- end
-
- protected
- def banner
- "Usage: #{$0} #{spec.name}"
- end
-
- def add_options!(opt)
- opt.separator ''
- opt.separator 'Options:'
- opt.on("--skip-migration",
- "Don't generate a migration file") { |v| options[:skip_migration] = v }
- opt.on("--test-unit",
- "Generate the Test::Unit compatible tests instead of RSpec") { |v| options[:test_unit] = v }
- opt.on("--haml",
- "Templates use haml") { |v| options[:haml] = v }
- end
-end
View
17 generators/oauth_provider/templates/_form.html.erb
@@ -1,17 +0,0 @@
-<%%= error_messages_for :client_application %>
-<div class="field">
- <label for="client_application_name">Name*</label><br/>
- <%%= f.text_field :name %>
-</div>
-<div class="field">
- <label for="client_application_url">Main Application URL*</label><br/>
- <%%= f.text_field :url %>
-</div>
-<div class="field">
- <label for="client_application_callback_url">Callback URL*</label><br/>
- <%%= f.text_field :callback_url %>
-</div>
-<div class="field">
- <label for="client_application_support_url">Support URL</label><br/>
- <%%= f.text_field :support_url %>
-</div>
View
21 generators/oauth_provider/templates/_form.html.haml
@@ -1,21 +0,0 @@
-=error_messages_for :client_application
-.field
- %label{:for=>"client_application_name"} Name*
- %br
- = f.text_field :name
-
-.field
- %label{:for=>"client_application_url"} Main Application URL*
- %br
- = f.text_field :url
-
-.field
- %label{:for=>"client_application_callback_url"} Callback URL*
- %br
- = f.text_field :callback_url
-
-.field
- %label{:for=>"client_application_support_url"} Support URL
- %br
- = f.text_field :support_url
-
View
16 generators/oauth_provider/templates/access_token.rb
@@ -1,16 +0,0 @@
-class AccessToken < OauthToken
- validates_presence_of :user, :secret
- before_create :set_authorized_at
-
- # Implement this to return a hash or array of the capabilities the access token has
- # This is particularly useful if you have implemented user defined permissions.
- # def capabilities
- # {:invalidate=>"/oauth/invalidate",:capabilities=>"/oauth/capabilities"}
- # end
-
- protected
-
- def set_authorized_at
- self.authorized_at = Time.now
- end
-end
View
14 generators/oauth_provider/templates/authorize.html.erb
@@ -1,14 +0,0 @@
-<h1>Authorize access to your account</h1>
-<p>Would you like to authorize <%%= link_to @token.client_application.name,@token.client_application.url %> (<%%= link_to @token.client_application.url,@token.client_application.url %>) to access your account?</p>
-<%% form_tag authorize_url do %>
- <%%= hidden_field_tag "oauth_token", @token.token %>
- <%%- if params[:oauth_callback] -%>
- <%%= hidden_field_tag "oauth_callback", params[:oauth_callback] %>
-<%%- end -%>
-<p>
- <%%= check_box_tag 'authorize' %> authorize access
-</p>
-<p>
- <%%= submit_tag %>
-</p>
-<%% end %>
View
16 generators/oauth_provider/templates/authorize.html.haml
@@ -1,16 +0,0 @@
-%h1 Authorize access to your account
-%p
- Would you like to authorize
- = link_to @token.client_application.name,@token.client_application.url
- (
- = link_to @token.client_application.url,@token.client_application.url
- ) to access your account?
-- form_tag authorize_url do
- = hidden_field_tag "oauth_token", @token.token
- - if params[:oauth_callback]
- = hidden_field_tag "oauth_callback", params[:oauth_callback]
- %p
- = check_box_tag 'authorize'
- authorize access
- %p
- = submit_tag
View
1  generators/oauth_provider/templates/authorize_failure.html.erb
@@ -1 +0,0 @@
-<h1>You have disallowed this request</h1>
View
1  generators/oauth_provider/templates/authorize_failure.html.haml
@@ -1 +0,0 @@
-%h1 You have disallowed this request
View
1  generators/oauth_provider/templates/authorize_success.html.erb
@@ -1 +0,0 @@
-<h1>You have allowed this request</h1>
View
1  generators/oauth_provider/templates/authorize_success.html.haml
@@ -1 +0,0 @@
-%h1 You have allowed this request
View
57 generators/oauth_provider/templates/client_application.rb
@@ -1,57 +0,0 @@
-require 'oauth'
-class ClientApplication < ActiveRecord::Base
- belongs_to :user
- has_many :tokens, :class_name => "OauthToken"
- has_many :access_tokens
- has_many :oauth2_verifiers
- has_many :oauth_tokens
- validates_presence_of :name, :url, :key, :secret
- validates_uniqueness_of :key
- before_validation_on_create :generate_keys
-
- validates_format_of :url, :with => /\Ahttp(s?):\/\/(\w+:{0,1}\w*@)?(\S+)(:[0-9]+)?(\/|\/([\w#!:.?+=&%@!\-\/]))?/i
- validates_format_of :support_url, :with => /\Ahttp(s?):\/\/(\w+:{0,1}\w*@)?(\S+)(:[0-9]+)?(\/|\/([\w#!:.?+=&%@!\-\/]))?/i, :allow_blank=>true
- validates_format_of :callback_url, :with => /\Ahttp(s?):\/\/(\w+:{0,1}\w*@)?(\S+)(:[0-9]+)?(\/|\/([\w#!:.?+=&%@!\-\/]))?/i, :allow_blank=>true
-
- attr_accessor :token_callback_url
-
- def self.find_token(token_key)
- token = OauthToken.find_by_token(token_key, :include => :client_application)
- if token && token.authorized?
- token
- else
- nil
- end
- end
-
- def self.verify_request(request, options = {}, &block)
- begin
- signature = OAuth::Signature.build(request, options, &block)
- return false unless OauthNonce.remember(signature.request.nonce, signature.request.timestamp)
- value = signature.verify
- value
- rescue OAuth::Signature::UnknownSignatureMethod => e
- false
- end
- end
-
- def oauth_server
- @oauth_server ||= OAuth::Server.new("http://your.site")
- end
-
- def credentials
- @oauth_client ||= OAuth::Consumer.new(key, secret)
- end
-
- # If your application requires passing in extra parameters handle it here
- def create_request_token(params={})
- RequestToken.create :client_application => self, :callback_url=>self.token_callback_url
- end
-
-protected
-
- def generate_keys
- self.key = OAuth::Helper.generate_key(40)[0,40]
- self.secret = OAuth::Helper.generate_key(40)[0,40]
- end
-end
View
29 generators/oauth_provider/templates/client_application_spec.rb
@@ -1,29 +0,0 @@
-require File.dirname(__FILE__) + '/../spec_helper'
-describe ClientApplication do
- fixtures :users, :client_applications, :oauth_tokens
- before(:each) do
- @application = ClientApplication.create :name => "Agree2", :url => "http://agree2.com", :user => users(:quentin)
- end
-
- it "should be valid" do
- @application.should be_valid
- end
-
-
- it "should not have errors" do
- @application.errors.full_messages.should == []
- end
-
- it "should have key and secret" do
- @application.key.should_not be_nil
- @application.secret.should_not be_nil
- end
-
- it "should have credentials" do
- @application.credentials.should_not be_nil
- @application.credentials.key.should == @application.key
- @application.credentials.secret.should == @application.secret
- end
-
-end
-
View
42 generators/oauth_provider/templates/client_application_test.rb
@@ -1,42 +0,0 @@
-require File.dirname(__FILE__) + '/../test_helper'
-module OAuthHelpers
-
- def create_consumer
- @consumer=OAuth::Consumer.new(@application.key,@application.secret,
- {
- :site=>@application.oauth_server.base_url
- })
- end
-
-end
-
-class ClientApplicationTest < ActiveSupport::TestCase
- include OAuthHelpers
- fixtures :users,:client_applications,:oauth_tokens
-
- def setup
- @application = ClientApplication.create :name => "Agree2", :url => "http://agree2.com", :user => users(:quentin)
- create_consumer
- end
-
- def test_should_be_valid
- assert @application.valid?
- end
-
-
- def test_should_not_have_errors
- assert_equal [], @application.errors.full_messages
- end
-
- def test_should_have_key_and_secret
- assert_not_nil @application.key
- assert_not_nil @application.secret
- end
-
- def test_should_have_credentials
- assert_not_nil @application.credentials
- assert_equal @application.key, @application.credentials.key
- assert_equal @application.secret, @application.credentials.secret
- end
-
-end
View
23 generators/oauth_provider/templates/client_applications.yml
@@ -1,23 +0,0 @@
-# Read about fixtures at http://ar.rubyonrails.org/classes/Fixtures.html
-one:
- id: 1
- name: MyString
- url: http://test.com
- support_url: http://test.com/support
- callback_url: http://test.com/callback
- key: one_key
- secret: MyString
- user_id: 1
- created_at: 2007-11-17 16:56:51
- updated_at: 2007-11-17 16:56:51
-two:
- id: 2
- name: MyString
- url: http://test.com
- support_url: http://test.com/support
- callback_url: http://test.com/callback
- key: two_key
- secret: MyString
- user_id: 1
- created_at: 2007-11-17 16:56:51
- updated_at: 2007-11-17 16:56:51
View
52 generators/oauth_provider/templates/clients_controller.rb
@@ -1,52 +0,0 @@
-class OauthClientsController < ApplicationController
- before_filter :login_required
- before_filter :get_client_application, :only => [:show, :edit, :update, :destroy]
-
- def index
- @client_applications = current_user.client_applications
- @tokens = current_user.tokens.find :all, :conditions => 'oauth_tokens.invalidated_at is null and oauth_tokens.authorized_at is not null'
- end
-
- def new
- @client_application = ClientApplication.new
- end
-
- def create
- @client_application = current_user.client_applications.build(params[:client_application])
- if @client_application.save
- flash[:notice] = "Registered the information successfully"
- redirect_to :action => "show", :id => @client_application.id
- else
- render :action => "new"
- end
- end
-
- def show
- end
-
- def edit
- end
-
- def update
- if @client_application.update_attributes(params[:client_application])
- flash[:notice] = "Updated the client information successfully"
- redirect_to :action => "show", :id => @client_application.id
- else
- render :action => "edit"
- end
- end
-
- def destroy
- @client_application.destroy
- flash[:notice] = "Destroyed the client application registration"
- redirect_to :action => "index"
- end
-
- private
- def get_client_application
- unless @client_application = current_user.client_applications.find(params[:id])
- flash.now[:error] = "Wrong application id"
- raise ActiveRecord::RecordNotFound
- end
- end
-end
View
176 generators/oauth_provider/templates/clients_controller_spec.rb
@@ -1,176 +0,0 @@
-require File.dirname(__FILE__) + '/../spec_helper'
-require File.dirname(__FILE__) + '/oauth_controller_spec_helper'
-require 'oauth/client/action_controller_request'
-
-describe OauthClientsController do
- if defined?(Devise)
- include Devise::TestHelpers
- end
- include OAuthControllerSpecHelper
- fixtures :client_applications, :oauth_tokens, :users
- before(:each) do
- login_as_application_owner
- end
-
- describe "index" do
- before do
- @client_applications = @user.client_applications
- end
-
- def do_get
- get :index
- end
-
- it "should be successful" do
- do_get
- response.should be_success
- end
-
- it "should assign client_applications" do
- do_get
- assigns[:client_applications].should==@client_applications
- end
-
- it "should render index template" do
- do_get
- response.should render_template('index')
- end
- end
-
- describe "show" do
-
- def do_get
- get :show, :id => '1'
- end
-
- it "should be successful" do
- do_get
- response.should be_success
- end
-
- it "should assign client_applications" do
- do_get
- assigns[:client_application].should == current_client_application
- end
-
- it "should render show template" do
- do_get
- response.should render_template('show')
- end
-
- end
-
- describe "new" do
-
- def do_get
- get :new
- end
-
- it "should be successful" do
- do_get
- response.should be_success
- end
-
- it "should assign client_applications" do
- do_get
- assigns[:client_application].class.should == ClientApplication
- end
-
- it "should render show template" do
- do_get
- response.should render_template('new')
- end
-
- end
-
- describe "edit" do
- def do_get
- get :edit, :id => '1'
- end
-
- it "should be successful" do
- do_get
- response.should be_success
- end
-
- it "should assign client_applications" do
- do_get
- assigns[:client_application].should == current_client_application
- end
-
- it "should render edit template" do
- do_get
- response.should render_template('edit')
- end
-
- end
-
- describe "create" do
-
- def do_valid_post
- post :create, 'client_application' => {'name' => 'my site', :url => "http://test.com"}
- @client_application = ClientApplication.last
- end
-
- def do_invalid_post
- post :create
- end
-
- it "should redirect to new client_application" do
- do_valid_post
- response.should be_redirect
- response.should redirect_to(:action => "show", :id => @client_application.id)
- end
-
- it "should render show template" do
- do_invalid_post
- response.should render_template('new')
- end
- end
-
- describe "destroy" do
-
- def do_delete
- delete :destroy, :id => '1'
- end
-
- it "should destroy client applications" do
- do_delete
- ClientApplication.should_not be_exists(1)
- end
-
- it "should redirect to list" do
- do_delete
- response.should be_redirect
- response.should redirect_to(:action => 'index')
- end
-
- end
-
- describe "update" do
-
- def do_valid_update
- put :update, :id => '1', 'client_application' => {'name' => 'updated site'}
- end
-
- def do_invalid_update
- put :update, :id => '1', 'client_application' => {'name' => nil}
- end
-
- it "should redirect to show client_application" do
- do_valid_update
- response.should be_redirect
- response.should redirect_to(:action => "show", :id => 1)
- end
-
- it "should assign client_applications" do
- do_invalid_update
- assigns[:client_application].should == ClientApplication.find(1)
- end
-
- it "should render show template" do
- do_invalid_update
- response.should render_template('edit')
- end
- end
-end
View
280 generators/oauth_provider/templates/clients_controller_test.rb
@@ -1,280 +0,0 @@
-require File.dirname(__FILE__) + '/../test_helper'
-require File.dirname(__FILE__) + '/../oauth_controller_test_helper'
-require 'oauth/client/action_controller_request'
-
-class OauthClientsController; def rescue_action(e) raise e end; end
-
-class OauthClientsControllerIndexTest < ActionController::TestCase
- include OAuthControllerTestHelper
- tests OauthClientsController
-
- def setup
- @controller = OauthClientsController.new
- @request = ActionController::TestRequest.new
- @response = ActionController::TestResponse.new
-
- login_as_application_owner
- end
-
- def do_get
- get :index
- end
-
- def test_should_be_successful
- do_get
- assert @response.success?
- end
-
- def test_should_query_current_users_client_applications
- @user.expects(:client_applications).returns(@client_applications)
- do_get
- end
-
- def test_should_assign_client_applications
- do_get
- assert_equal @client_applications, assigns(:client_applications)
- end
-
- def test_should_render_index_template
- do_get
- assert_template 'index'
- end
-end
-
-class OauthClientsControllerShowTest < ActionController::TestCase
- include OAuthControllerTestHelper
- tests OauthClientsController
-
- def setup
- @controller = OauthClientsController.new
- @request = ActionController::TestRequest.new
- @response = ActionController::TestResponse.new
-
- login_as_application_owner
- end
-
- def do_get
- get :show, :id => '3'
- end
-
- def test_should_be_successful
- do_get
- assert @response.success?
- end
-
- def test_should_query_current_users_client_applications
- @user.expects(:client_applications).returns(@client_applications)
- @client_applications.expects(:find).with('3').returns(@client_application)
- do_get
- end
-
- def test_should_assign_client_applications
- do_get
- assert_equal @client_application, assigns(:client_application)
- end
-
- def test_should_render_show_template
- do_get
- assert_template 'show'
- end
-
-end
-
-class OauthClientsControllerNewTest < ActionController::TestCase
- include OAuthControllerTestHelper
- tests OauthClientsController
-
- def setup
- @controller = OauthClientsController.new
- @request = ActionController::TestRequest.new
- @response = ActionController::TestResponse.new
-
- login_as_application_owner
- ClientApplication.stubs(:new).returns(@client_application)
- end
-
- def do_get
- get :new
- end
-
- def test_should_be_successful
- do_get
- assert @response.success?
- end
-
- def test_should_assign_client_applications
- do_get
- assert_equal @client_application, assigns(:client_application)
- end
-
- def test_should_render_show_template
- do_get
- assert_template 'new'
- end
-
-end
-
-class OauthClientsControllerEditTest < ActionController::TestCase
- include OAuthControllerTestHelper
- tests OauthClientsController
-
- def setup
- @controller = OauthClientsController.new
- @request = ActionController::TestRequest.new
- @response = ActionController::TestResponse.new
-
- login_as_application_owner
- end
-
- def do_get
- get :edit, :id=>'3'
- end
-
- def test_should_be_successful
- do_get
- assert @response.success?
- end
-
- def test_should_query_current_users_client_applications
- @user.expects(:client_applications).returns(@client_applications)
- @client_applications.expects(:find).with('3').returns(@client_application)
- do_get
- end
-
- def test_should_assign_client_applications
- do_get
- assert_equal @client_application, assigns(:client_application)
- end
-
- def test_should_render_edit_template
- do_get
- assert_template 'edit'
- end
-
-end
-
-class OauthClientsControllerCreateTest < ActionController::TestCase
- include OAuthControllerTestHelper
- tests OauthClientsController
-
- def setup
- @controller = OauthClientsController.new
- @request = ActionController::TestRequest.new
- @response = ActionController::TestResponse.new
-
- login_as_application_owner
- @client_applications.stubs(:build).returns(@client_application)
- @client_application.stubs(:save).returns(true)
- end
-
- def do_valid_post
- @client_application.expects(:save).returns(true)
- post :create,'client_application' => {'name' => 'my site'}
- end
-
- def do_invalid_post
- @client_application.expects(:save).returns(false)
- post :create,:client_application=>{:name => 'my site'}
- end
-
- def test_should_query_current_users_client_applications
- @client_applications.expects(:build).returns(@client_application)
- do_valid_post
- end
-
- def test_should_redirect_to_new_client_application
- do_valid_post
- assert_response :redirect
- assert_redirected_to(:action => "show", :id => @client_application.id)
- end
-
- def test_should_assign_client_applications
- do_invalid_post
- assert_equal @client_application, assigns(:client_application)
- end
-
- def test_should_render_show_template
- do_invalid_post
- assert_template('new')
- end
-end
-
-class OauthClientsControllerDestroyTest < ActionController::TestCase
- include OAuthControllerTestHelper
- tests OauthClientsController
-
- def setup
- @controller = OauthClientsController.new
- @request = ActionController::TestRequest.new
- @response = ActionController::TestResponse.new
-
- login_as_application_owner
- @client_application.stubs(:destroy)
- end
-
- def do_delete
- delete :destroy,:id=>'3'
- end
-
- def test_should_query_current_users_client_applications
- @user.expects(:client_applications).returns(@client_applications)
- @client_applications.expects(:find).with('3').returns(@client_application)
- do_delete
- end
-
- def test_should_destroy_client_applications
- @client_application.expects(:destroy)
- do_delete
- end
-
- def test_should_redirect_to_list
- do_delete
- assert_response :redirect
- assert_redirected_to :action => 'index'
- end
-
-end
-
-class OauthClientsControllerUpdateTest < ActionController::TestCase
- include OAuthControllerTestHelper
- tests OauthClientsController
-
- def setup
- @controller = OauthClientsController.new
- @request = ActionController::TestRequest.new
- @response = ActionController::TestResponse.new
- login_as_application_owner
- end
-
- def do_valid_update
- @client_application.expects(:update_attributes).returns(true)
- put :update, :id => '1', 'client_application' => {'name' => 'my site'}
- end
-
- def do_invalid_update
- @client_application.expects(:update_attributes).returns(false)
- put :update, :id=>'1', 'client_application' => {'name' => 'my site'}
- end
-
- def test_should_query_current_users_client_applications
- @user.expects(:client_applications).returns(@client_applications)
- @client_applications.expects(:find).with('1').returns(@client_application)
- do_valid_update
- end
-
- def test_should_redirect_to_new_client_application
- do_valid_update
- assert_response :redirect
- assert_redirected_to :action => "show", :id => @client_application.id
- end
-
- def test_should_assign_client_applications
- do_invalid_update
- assert_equal @client_application, assigns(:client_application)
- end
-
- def test_should_render_show_template
- do_invalid_update
- assert_template('edit')
- end
-end
View
23 generators/oauth_provider/templates/controller.rb
@@ -1,23 +0,0 @@
-require 'oauth/controllers/provider_controller'
-class OauthController < ApplicationController
- include OAuth::Controllers::ProviderController
-
- protected
- # Override this to match your authorization page form
- # It currently expects a checkbox called authorize
- # def user_authorizes_token?
- # params[:authorize] == '1'
- # end
-
- # should authenticate and return a user if valid password.
- # This example should work with most Authlogic or Devise. Uncomment it
- # def authenticate_user(username,password)
- # user = User.find_by_email params[:username]
- # if user && user.valid_password?(params[:password])
- # user
- # else
- # nil
- # end
- # end
-
-end
View
7 generators/oauth_provider/templates/edit.html.erb
@@ -1,7 +0,0 @@
-<h1>Edit your application</h1>
-<%% form_for :client_application, @client_application, :url => oauth_client_path(@client_application), :html => {:method => :put} do |f| %>
- <%%= render :partial => "form", :locals => { :f => f } %>
- <%%= submit_tag "Edit" %>
-<%% end %>
-<%%= link_to 'Show', oauth_client_path(@client_application) %> |
-<%%= link_to 'Back', oauth_clients_path %>
View
4 generators/oauth_provider/templates/edit.html.haml
@@ -1,4 +0,0 @@
-%h1 Edit your application
-- form_for :client_application do |f|
- = render :partial => "form", :locals => { :f => f }
- = submit_tag "Edit"
View
43 generators/oauth_provider/templates/index.html.erb
@@ -1,43 +0,0 @@
-<div class="flash"><%%= flash[:notice] %></div>
-<h1>OAuth Client Applications</h1>
-<%% unless @tokens.empty? %>
-<p>The following tokens have been issued to applications in your name</p>
-<table>
- <tr><th>Application</th><th>Issued</th><th>&nbsp;</th></tr>
- <%% @tokens.each do |token|%>
- <%% content_tag_for :tr, token do %>
- <td><%%= link_to token.client_application.name, token.client_application.url %></td>
- <td><%%= token.authorized_at %></td>
- <td>
- <%% form_tag :controller => 'oauth', :action => 'revoke' do %>
- <%%= hidden_field_tag 'token', token.token %>
- <%%= submit_tag "Revoke!" %>
- <%% end %>
- </td>
- <%% end %>
- <%% end %>
-
-</table>
-<%% end %>
-<h3>Application Developers</h3>
-<%% if @client_applications.empty? %>
- <p>
- Do you have an application you would like to register for use with us using the <a href="http://oauth.net">OAuth</a> standard?
- </p>
- <p>
- You must register your web application before it can make OAuth requests to this service
- </p>
-<%% else %>
- <p>
- You have the following client applications registered:
- </p>
- <%% @client_applications.each do |client|%>
- <%% div_for client do %>
- <%%= link_to client.name, oauth_client_path(client) %>-
- <%%= link_to 'Edit', edit_oauth_client_path(client) %>
- <%%= link_to 'Delete', oauth_client_path(client), :confirm => "Are you sure?", :method => :delete %>
- <%% end %>
- <%% end %>
-<%% end %>
-<br />
-<h3><%%= link_to "Register your application", :action => :new %></h3>
View
39 generators/oauth_provider/templates/index.html.haml
@@ -1,39 +0,0 @@
-.flash= flash[:notice]
-%h1 OAuth Client Applications
-- unless @tokens.empty?
-
- %p
- The following tokens have been issued to applications in your name
-
- %table
- %tr
- %th Application
- %th Issued
- %th &nbsp;
- - @tokens.each do |token|
- - content_tag_for :tr, token do
- %td= link_to token.client_application.name, token.client_application.url
- %td= token.authorized_at
- %td
- - form_tag :controller => 'oauth', :action => 'revoke' do
- = hidden_field_tag 'token', token.token
- = submit_tag "Revoke!"
-
-%h3 Application Developers
-
-- if @client_applications.empty?
- %p
- Do you have an application you would like to register for use with us using the <a href="http://oauth.net">OAuth</a> standard?
- You must register your web application before it can make OAuth requests to this service
-- else
- %p
- You have the following client applications registered:
-
- - @client_applications.each do |client|
- - div_for client do
- = link_to client.name, :action => :show, :id => client.id
- = link_to 'Edit', edit_oauth_client_path(client)
- = link_to 'Delete', oauth_client_path(client), :confirm => "Are you sure?", :method => :delete
-%br
-%h3
- = link_to "Register your application", :action => :new
View
47 generators/oauth_provider/templates/migration.rb
@@ -1,47 +0,0 @@
-class CreateOauthTables < ActiveRecord::Migration
- def self.up
- create_table :client_applications do |t|
- t.string :name
- t.string :url
- t.string :support_url
- t.string :callback_url
- t.string :key, :limit => 40
- t.string :secret, :limit => 40
- t.integer :user_id
-
- t.timestamps
- end
- add_index :client_applications, :key, :unique => true
-
- create_table :oauth_tokens do |t|
- t.integer :user_id
- t.string :type, :limit => 20
- t.integer :client_application_id
- t.string :token, :limit => 40
- t.string :secret, :limit => 40
- t.string :callback_url
- t.string :verifier, :limit => 20
- t.string :scope
- t.timestamp :authorized_at, :invalidated_at, :expires_at
- t.timestamps
- end
-
- add_index :oauth_tokens, :token, :unique => true
-
- create_table :oauth_nonces do |t|
- t.string :nonce
- t.integer :timestamp
-
- t.timestamps
- end
- add_index :oauth_nonces,[:nonce, :timestamp], :unique
-
- end
-
- def self.down
- drop_table :client_applications
- drop_table :oauth_tokens
- drop_table :oauth_nonces
- end
-
-end
View
5 generators/oauth_provider/templates/new.html.erb
@@ -1,5 +0,0 @@
-<h1>Register a new application</h1>
-<%% form_for :client_application, :url => { :action => :create } do |f| %>
- <%%= render :partial => "form", :locals => { :f => f } %>
- <%%= submit_tag "Register" %>
-<%% end %>
View
5 generators/oauth_provider/templates/new.html.haml
@@ -1,5 +0,0 @@
-%h1 Register a new application
-
-- form_for :client_application, :url => { :action => :create } do |f|
- = render :partial => "form", :locals => { :f => f }
- = submit_tag "Register"
View
16 generators/oauth_provider/templates/oauth2_authorize.html.erb
@@ -1,16 +0,0 @@
-<h1>Authorize access to your account</h1>
-<p>Would you like to authorize <%%= link_to @token.client_application.name,@token.client_application.url %> (<%%= link_to @token.client_application.url,@token.client_application.url %>) to access your account?</p>
-<%% form_tag authorize_url do %>
- <%%= hidden_field_tag "response_type", params[:response_type]%>
- <%%= hidden_field_tag "client_id", params[:client_id]%>
- <%%= hidden_field_tag "redirect_uri", params[:redirect_uri]%>
- <%%= hidden_field_tag "state", params[:state]%>
- <%%= hidden_field_tag "scope", params[:scope]%>
-
-<p>
- <%%= check_box_tag 'authorize' %> authorize access
-</p>
-<p>
- <%%= submit_tag %>
-</p>
-<%% end %>
View
17 generators/oauth_provider/templates/oauth2_authorize.html.haml
@@ -1,17 +0,0 @@
-%h1 Authorize access to your account
-%p
- Would you like to authorize
- = link_to @client_application.name,@client_application.url
- (
- = link_to @client_application.url,@client_application.url
- ) to access your account?
-- form_tag authorize_url do
- = hidden_field_tag "response_type", params[:response_type]
- = hidden_field_tag "client_id", params[:client_id]
- = hidden_field_tag "redirect_uri", params[:redirect_uri]
- = hidden_field_tag "state", params[:state]
- = hidden_field_tag "scope", params[:scope]
- = check_box_tag 'authorize'
- authorize access
- %p
- = submit_tag
View
20 generators/oauth_provider/templates/oauth2_token.rb
@@ -1,20 +0,0 @@
-class Oauth2Token < AccessToken
- attr_accessor :state
- def as_json(options={})
- d = {:access_token=>token, :token_type => 'bearer'}
- d[:expires_in] = expires_in if expires_at
- d
- end
-
- def to_query
- q = "access_token=#{token}&token_type=bearer"
- q << "&state=#{URI.escape(state)}" if @state
- q << "&expires_in=#{expires_in}" if expires_at
- q << "&scope=#{URI.escape(scope)}" if scope
- q
- end
-
- def expires_in
- expires_at.to_i - Time.now.to_i
- end
-end
View
52 generators/oauth_provider/templates/oauth2_token_spec.rb
@@ -1,52 +0,0 @@
-require File.dirname(__FILE__) + '/../spec_helper'
-
-describe Oauth2Token do
- fixtures :client_applications, :users, :oauth_tokens
- before(:each) do
- @token = Oauth2Token.create :client_application => client_applications(:one), :user=>users(:aaron)
- end
-
- it "should be valid" do
- @token.should be_valid
- end
-
- it "should have a token" do
- @token.token.should_not be_nil
- end
-
- it "should have a secret" do
- @token.secret.should_not be_nil
- end
-
- it "should be authorized" do
- @token.should be_authorized
- end
-
- it "should not be invalidated" do
- @token.should_not be_invalidated
- end
-
- it "should generate correct json and query strong" do
- @token.as_json.should == {:access_token => @token.token, :token_type => 'bearer'}
- @token.to_query.should == "access_token=#{@token.token}&token_type=bearer"
- end
-
- it "should generate correct json and query string and include state in query if present" do
- @token.state = 'bb bb'
- @token.as_json.should == {:access_token => @token.token, :token_type => 'bearer'}
- @token.to_query.should == "access_token=#{@token.token}&token_type=bearer&state=bb%20bb"
- end
-
- it "should generate correct json and query string and include scope in query if present" do
- @token.scope = 'bbbb aaaa'
- @token.as_json.should == {:access_token => @token.token, :token_type => 'bearer'}
- @token.to_query.should == "access_token=#{@token.token}&token_type=bearer&scope=bbbb%20aaaa"
- end
-
- it "should generate correct json and include expires_in if present" do
- @token.expires_at = 1.hour.from_now
- @token.as_json.should == { :access_token => @token.token, :token_type => 'bearer', :expires_in => 3600 }
- @token.to_query.should == "access_token=#{@token.token}&token_type=bearer&expires_in=3600"
- end
-
-end
View
35 generators/oauth_provider/templates/oauth2_verifier.rb
@@ -1,35 +0,0 @@
-class Oauth2Verifier < OauthToken
- validates_presence_of :user
- attr_accessor :state
-
- def exchange!(params={})
- OauthToken.transaction do
- token = Oauth2Token.create! :user=>user,:client_application=>client_application, :scope => scope
- invalidate!
- token
- end
- end
-
- def code
- token
- end
-
- def redirect_url
- callback_url
- end
-
- def to_query
- q = "code=#{token}"
- q << "&state=#{URI.escape(state)}" if @state
- q
- end
-
- protected
-
- def generate_keys
- self.token = OAuth::Helper.generate_key(20)[0,20]
- self.expires_at = 10.minutes.from_now
- self.authorized_at = Time.now
- end
-
-end
View
44 generators/oauth_provider/templates/oauth2_verifier_spec.rb
@@ -1,44 +0,0 @@
-require File.dirname(__FILE__) + '/../spec_helper'
-
-describe Oauth2Verifier do
- fixtures :client_applications, :users, :oauth_tokens
- before(:each) do
- @verifier = Oauth2Verifier.create :client_application => client_applications(:one), :user=>users(:aaron), :scope => "bbbb aaaa"
- end
-
- it "should be valid" do
- @verifier.should be_valid
- end
-
- it "should have a code" do
- @verifier.code.should_not be_nil
- end
-
- it "should not have a secret" do
- @verifier.secret.should be_nil
- end
-
- it "should be authorized" do
- @verifier.should be_authorized
- end
-
- it "should not be invalidated" do
- @verifier.should_not be_invalidated
- end
-
- it "should generate query string" do
- @verifier.to_query.should == "code=#{@verifier.code}"
- @verifier.state="bbbb aaaa"
- @verifier.to_query.should == "code=#{@verifier.code}&state=bbbb%20aaaa"
- end
-
- it "should properly exchange for token" do
- @token = @verifier.exchange!
- @verifier.should be_invalidated
- @token.user.should==@verifier.user
- @token.client_application.should == @verifier.client_application
- @token.should be_authorized
- @token.should_not be_invalidated
- @token.scope.should == @verifier.scope
- end
-end
View
13 generators/oauth_provider/templates/oauth_nonce.rb
@@ -1,13 +0,0 @@
-# Simple store of nonces. The OAuth Spec requires that any given pair of nonce and timestamps are unique.
-# Thus you can use the same nonce with a different timestamp and viceversa.
-class OauthNonce < ActiveRecord::Base
- validates_presence_of :nonce, :timestamp
- validates_uniqueness_of :nonce, :scope => :timestamp
-
- # Remembers a nonce and it's associated timestamp. It returns false if it has already been used
- def self.remember(nonce, timestamp)
- oauth_nonce = OauthNonce.create(:nonce => nonce, :timestamp => timestamp)
- return false if oauth_nonce.new_record?
- oauth_nonce
- end
-end
View
24 generators/oauth_provider/templates/oauth_nonce_spec.rb
@@ -1,24 +0,0 @@
-require File.dirname(__FILE__) + '/../spec_helper'
-require 'oauth/helper'
-describe OauthNonce do
- include OAuth::Helper
- before(:each) do
- @oauth_nonce = OauthNonce.remember(generate_key, Time.now.to_i)
- end
-
- it "should be valid" do
- @oauth_nonce.should be_valid
- end
-
- it "should not have errors" do
- @oauth_nonce.errors.full_messages.should == []
- end
-
- it "should not be a new record" do
- @oauth_nonce.should_not be_new_record
- end
-
- it "should not allow a second one with the same values" do
- OauthNonce.remember(@oauth_nonce.nonce,@oauth_nonce.timestamp).should == false
- end
-end
View
26 generators/oauth_provider/templates/oauth_nonce_test.rb
@@ -1,26 +0,0 @@
-require File.dirname(__FILE__) + '/../test_helper'
-require 'oauth/helper'
-
-class ClientNoneTest < ActiveSupport::TestCase
- include OAuth::Helper
-
- def setup
- @oauth_nonce = OauthNonce.remember(generate_key,Time.now.to_i)
- end
-
- def test_should_be_valid
- assert @oauth_nonce.valid?
- end
-
- def test_should_not_have_errors
- assert_equal [], @oauth_nonce.errors.full_messages
- end
-
- def test_should_not_be_a_new_record
- assert !@oauth_nonce.new_record?
- end
-
- def test_shuold_not_allow_a_second_one_with_the_same_values
- assert_equal false, OauthNonce.remember(@oauth_nonce.nonce, @oauth_nonce.timestamp)
- end
-end
View
13 generators/oauth_provider/templates/oauth_nonces.yml
@@ -1,13 +0,0 @@
-# Read about fixtures at http://ar.rubyonrails.org/classes/Fixtures.html
-one:
- id: 1
- nonce: a_nonce
- timestamp: 1
- created_at: 2007-11-25 17:27:04
- updated_at: 2007-11-25 17:27:04
-two:
- id: 2
- nonce: b_nonce
- timestamp: 2
- created_at: 2007-11-25 17:27:04
- updated_at: 2007-11-25 17:27:04
View
30 generators/oauth_provider/templates/oauth_token.rb
@@ -1,30 +0,0 @@
-class OauthToken < ActiveRecord::Base
- belongs_to :client_application
- belongs_to :user
- validates_uniqueness_of :token
- validates_presence_of :client_application, :token
- before_validation_on_create :generate_keys
-
- def invalidated?
- invalidated_at != nil
- end
-
- def invalidate!
- update_attribute(:invalidated_at, Time.now)
- end
-
- def authorized?
- authorized_at != nil && !invalidated?
- end
-
- def to_query
- "oauth_token=#{token}&oauth_token_secret=#{secret}"
- end
-
- protected
-
- def generate_keys
- self.token = OAuth::Helper.generate_key(40)[0,40]
- self.secret = OAuth::Helper.generate_key(40)[0,40]
- end
-end
View
309 generators/oauth_provider/templates/oauth_token_spec.rb
@@ -1,309 +0,0 @@
-require File.dirname(__FILE__) + '/../spec_helper'
-
-describe RequestToken do
- fixtures :client_applications, :users, :oauth_tokens
- before(:each) do
- @token = RequestToken.create :client_application => client_applications(:one)
- end
-
- it "should be valid" do
- @token.should be_valid
- end
-
- it "should not have errors" do
- @token.errors.should_not == []
- end
-
- it "should have a token" do
- @token.token.should_not be_nil
- end
-
- it "should have a secret" do
- @token.secret.should_not be_nil
- end
-
- it "should not be authorized" do
- @token.should_not be_authorized
- end
-
- it "should not be invalidated" do
- @token.should_not be_invalidated
- end
-
- it "should not have a verifier" do
- @token.verifier.should be_nil
- end
-
- it "should not be oob" do
- @token.should_not be_oob
- end
-
- describe "OAuth 1.0a" do
-
- describe "with provided callback" do
- before(:each) do
- @token.callback_url="http://test.com/callback"
- end
-
- it "should not be oauth10" do
- @token.should_not be_oauth10
- end
-
- it "should not be oob" do
- @token.should_not be_oob
- end
-
- describe "authorize request" do
- before(:each) do
- @token.authorize!(users(:quentin))
- end
-
- it "should be authorized" do
- @token.should be_authorized
- end
-
- it "should have authorized at" do
- @token.authorized_at.should_not be_nil
- end
-
- it "should have user set" do
- @token.user.should == users(:quentin)
- end
-
- it "should have verifier" do
- @token.verifier.should_not be_nil
- end
-
- describe "exchange for access token" do
-
- before(:each) do
- @token.provided_oauth_verifier=@token.verifier
- @access = @token.exchange!
- end
-
- it "should be valid" do
- @access.should be_valid
- end
-
- it "should have no error messages" do
- @access.errors.full_messages.should==[]
- end
-
- it "should invalidate request token" do
- @token.should be_invalidated
- end
-
- it "should set user on access token" do
- @access.user.should == users(:quentin)
- end
-
- it "should authorize accesstoken" do
- @access.should be_authorized
- end
- end
-
- describe "attempt exchange with invalid verifier (OAuth 1.0a)" do
-
- before(:each) do
- @value = @token.exchange!
- end
-
- it "should return false" do
- @value.should==false
- end
-
- it "should not invalidate request token" do
- @token.should_not be_invalidated
- end
- end
-
- end
-
- describe "attempt exchange with out authorization" do
-
- before(:each) do
- @value = @token.exchange!
- end
-
- it "should return false" do
- @value.should==false
- end
-
- it "should not invalidate request token" do
- @token.should_not be_invalidated
- end
- end
-
- it "should return 1.0a style to_query" do
- @token.to_query.should=="oauth_token=#{@token.token}&oauth_token_secret=#{@token.secret}&oauth_callback_confirmed=true"
- end
-
- end
-
- describe "with oob callback" do
- before(:each) do
- @token.callback_url='oob'
- end
-
- it "should not be oauth10" do
- @token.should_not be_oauth10
- end
-
- it "should be oob" do
- @token.should be_oob
- end
-
- describe "authorize request" do
- before(:each) do
- @token.authorize!(users(:quentin))
- end
-
- it "should be authorized" do
- @token.should be_authorized
- end
-
- it "should have authorized at" do
- @token.authorized_at.should_not be_nil
- end
-
- it "should have user set" do
- @token.user.should == users(:quentin)
- end
-
- it "should have verifier" do
- @token.verifier.should_not be_nil
- end
-
- describe "exchange for access token" do
-
- before(:each) do
- @token.provided_oauth_verifier=@token.verifier
- @access = @token.exchange!
- end
-
- it "should invalidate request token" do
- @token.should be_invalidated
- end
-
- it "should set user on access token" do
- @access.user.should == users(:quentin)
- end
-
- it "should authorize accesstoken" do
- @access.should be_authorized
- end
- end
-
- describe "attempt exchange with invalid verifier (OAuth 1.0a)" do
-
- before(:each) do
- @value = @token.exchange!
- end
-
- it "should return false" do
- @value.should==false
- end
-
- it "should not invalidate request token" do
- @token.should_not be_invalidated
- end
- end
-
- end
-
- describe "attempt exchange with out authorization invalid verifier" do
-
- before(:each) do
- @value = @token.exchange!
- end
-
- it "should return false" do
- @value.should==false
- end
-
- it "should not invalidate request token" do
- @token.should_not be_invalidated
- end
- end
-
- it "should return 1.0 style to_query" do
- @token.to_query.should=="oauth_token=#{@token.token}&oauth_token_secret=#{@token.secret}&oauth_callback_confirmed=true"
- end
- end
- end
-
- if defined? OAUTH_10_SUPPORT && OAUTH_10_SUPPORT
- describe "OAuth 1.0" do
-
- it "should be oauth10" do
- @token.should be_oauth10
- end
-
- it "should not be oob" do
- @token.should_not be_oob
- end
-
- describe "authorize request" do
- before(:each) do
- @token.authorize!(users(:quentin))
- end
-
- it "should be authorized" do
- @token.should be_authorized
- end
-
- it "should have authorized at" do
- @token.authorized_at.should_not be_nil
- end
-
- it "should have user set" do
- @token.user.should == users(:quentin)
- end
-
- it "should not have verifier" do
- @token.verifier.should be_nil
- end
-
- describe "exchange for access token" do
-
- before(:each) do
- @access = @token.exchange!
- end
-
- it "should invalidate request token" do
- @token.should be_invalidated
- end
-
- it "should set user on access token" do
- @access.user.should == users(:quentin)
- end
-
- it "should authorize accesstoken" do
- @access.should be_authorized
- end
- end
-
- end
-
- describe "attempt exchange with out authorization" do
-
- before(:each) do
- @value = @token.exchange!
- end
-
- it "should return false" do
- @value.should==false
- end
-
- it "should not invalidate request token" do
- @token.should_not be_invalidated
- end
- end
-
- it "should return 1.0 style to_query" do
- @token.to_query.should=="oauth_token=#{@token.token}&oauth_token_secret=#{@token.secret}"
- end
-
- end
- end
-end
View
57 generators/oauth_provider/templates/oauth_token_test.rb
@@ -1,57 +0,0 @@
-require File.dirname(__FILE__) + '/../test_helper'
-
-class RequestTokenTest < ActiveSupport::TestCase
-
- fixtures :client_applications, :users, :oauth_tokens
-
- def setup
- @token = RequestToken.create :client_application=>client_applications(:one)
- end
-
- def test_should_be_valid
- assert @token.valid?
- end
-
- def test_should_not_have_errors
- assert @token.errors.empty?
- end
-
- def test_should_have_a_token
- assert_not_nil @token.token
- end
-
- def test_should_have_a_secret
- assert_not_nil @token.secret
- end
-