From cab0213b37b63cee7197aa24840e32b8b557c698 Mon Sep 17 00:00:00 2001
From: "Gun.io Whitespace Robot"
Date: Sat, 29 Oct 2011 01:00:39 -0400
Subject: [PATCH] Remove whitespace [Gun.io WhitespaceBot]
---
UPGRADE.rdoc | 2 +-
.../oauth_consumer_generator.rb | 18 +--
.../templates/consumer_token.rb | 6 +-
.../oauth_consumer/templates/controller.rb | 10 +-
.../oauth_consumer/templates/migration.rb | 6 +-
.../oauth_consumer/templates/oauth_config.rb | 6 +-
.../oauth_consumer/templates/show.html.haml | 2 +-
generators/oauth_provider/USAGE | 2 +-
.../oauth_provider/lib/insert_routes.rb | 16 +--
.../oauth_provider_generator.rb | 20 ++--
.../oauth_provider/templates/_form.html.haml | 8 +-
.../oauth_provider/templates/access_token.rb | 8 +-
.../templates/client_application.rb | 16 +--
.../templates/client_application_spec.rb | 10 +-
.../templates/client_application_test.rb | 14 +--
.../templates/clients_controller.rb | 8 +-
.../templates/clients_controller_spec.rb | 60 +++++-----
.../templates/clients_controller_test.rb | 108 +++++++++---------
.../oauth_provider/templates/controller.rb | 6 +-
.../oauth_provider/templates/index.html.erb | 4 +-
.../oauth_provider/templates/index.html.haml | 4 +-
.../oauth_provider/templates/migration.rb | 8 +-
.../templates/oauth2_authorize.html.erb | 2 +-
.../oauth_provider/templates/oauth_nonce.rb | 2 +-
.../templates/oauth_nonce_spec.rb | 6 +-
.../templates/oauth_nonce_test.rb | 8 +-
.../oauth_provider/templates/oauth_token.rb | 12 +-
.../templates/oauth_token_spec.rb | 76 ++++++------
.../templates/oauth_token_test.rb | 20 ++--
.../oauth_provider/templates/request_token.rb | 14 +--
.../oauth_provider/templates/show.html.haml | 6 +-
init.rb | 2 +-
.../consumer_token.rb | 6 +-
.../oauth_consumer_templates/migration.rb | 6 +-
.../oauth_provider_templates/request_token.rb | 2 +-
.../oauth_consumer_templates/show.html.haml | 2 +-
.../consumer_token.rb | 12 +-
.../oauth_provider_templates/request_token.rb | 2 +-
.../oauth_consumer_generator.rb | 12 +-
.../oauth_consumer/templates/controller.rb | 20 ++--
.../oauth_consumer/templates/oauth_config.rb | 6 +-
.../application_controller_methods.rb | 38 +++---
lib/oauth/controllers/consumer_controller.rb | 28 ++---
lib/oauth/models/consumers/service_loader.rb | 2 +-
.../models/consumers/services/agree2_token.rb | 4 +-
.../consumers/services/fireeagle_token.rb | 14 +--
.../models/consumers/services/oauth2_token.rb | 14 +--
.../consumers/services/opentransact_token.rb | 8 +-
.../consumers/services/picomoney_token.rb | 4 +-
.../consumers/services/twitter_token.rb | 10 +-
lib/oauth/models/consumers/simple_client.rb | 10 +-
lib/oauth/models/consumers/token.rb | 28 ++---
52 files changed, 359 insertions(+), 359 deletions(-)
diff --git a/UPGRADE.rdoc b/UPGRADE.rdoc
index 6cc4dab9..92d0d9ff 100644
--- a/UPGRADE.rdoc
+++ b/UPGRADE.rdoc
@@ -1,7 +1,7 @@
A few non backwards compatible changes have been made that are really easy to fix.
If you are upgrading a oauth_consumer from 0.3.x to 0.4.x add the following line to your consumer_token model:
-
+
belongs_to :user
So it looks like this:
diff --git a/generators/oauth_consumer/oauth_consumer_generator.rb b/generators/oauth_consumer/oauth_consumer_generator.rb
index 762e7550..8c2fcc6a 100644
--- a/generators/oauth_consumer/oauth_consumer_generator.rb
+++ b/generators/oauth_consumer/oauth_consumer_generator.rb
@@ -5,26 +5,26 @@ class OauthConsumerGenerator < Rails::Generator::Base
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]
+
+ unless options[:skip_migration]
m.migration_template 'migration.rb', 'db/migrate', :assigns => {
:migration_name => "CreateOauthConsumerTokens"
}, :migration_file_name => "create_oauth_consumer_tokens"
@@ -40,11 +40,11 @@ def banner
def add_options!(opt)
opt.separator ''
opt.separator 'Options:'
- opt.on("--skip-migration",
+ opt.on("--skip-migration",
"Don't generate a migration file") { |v| options[:skip_migration] = v }
-# opt.on("--test-unit",
+# opt.on("--test-unit",
# "Generate the Test::Unit compatible tests instead of RSpec") { |v| options[:test_unit] = v }
- opt.on("--haml",
+ opt.on("--haml",
"Templates use haml") { |v| options[:haml] = v }
end
end
diff --git a/generators/oauth_consumer/templates/consumer_token.rb b/generators/oauth_consumer/templates/consumer_token.rb
index e19663b4..12eaf2e6 100644
--- a/generators/oauth_consumer/templates/consumer_token.rb
+++ b/generators/oauth_consumer/templates/consumer_token.rb
@@ -1,11 +1,11 @@
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
\ No newline at end of file
diff --git a/generators/oauth_consumer/templates/controller.rb b/generators/oauth_consumer/templates/controller.rb
index d77d3089..40a5b193 100644
--- a/generators/oauth_consumer/templates/controller.rb
+++ b/generators/oauth_consumer/templates/controller.rb
@@ -1,12 +1,12 @@
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
@@ -14,14 +14,14 @@ def callback
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
diff --git a/generators/oauth_consumer/templates/migration.rb b/generators/oauth_consumer/templates/migration.rb
index afa3f6a3..310044ed 100644
--- a/generators/oauth_consumer/templates/migration.rb
+++ b/generators/oauth_consumer/templates/migration.rb
@@ -1,6 +1,6 @@
class CreateOauthConsumerTokens < ActiveRecord::Migration
def self.up
-
+
create_table :consumer_tokens do |t|
t.integer :user_id
t.string :type, :limit => 30
@@ -8,9 +8,9 @@ def self.up
t.string :secret
t.timestamps
end
-
+
add_index :consumer_tokens, :token, :unique => true
-
+
end
def self.down
diff --git a/generators/oauth_consumer/templates/oauth_config.rb b/generators/oauth_consumer/templates/oauth_config.rb
index 1c1d422c..01736148 100644
--- a/generators/oauth_consumer/templates/oauth_config.rb
+++ b/generators/oauth_consumer/templates/oauth_config.rb
@@ -58,15 +58,15 @@
# :nu_bux => {
# :key => "",
# :secret => "",
-# :super_class => "OpenTransactToken", # if a OAuth service follows a particular standard
+# :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"
+# :site => "http://nubux.heroku.com"
# }
# }
# }
-#
+#
OAUTH_CREDENTIALS = {
} unless defined? OAUTH_CREDENTIALS
diff --git a/generators/oauth_consumer/templates/show.html.haml b/generators/oauth_consumer/templates/show.html.haml
index e7358b0b..cabe6d5d 100644
--- a/generators/oauth_consumer/templates/show.html.haml
+++ b/generators/oauth_consumer/templates/show.html.haml
@@ -1,4 +1,4 @@
-%h1
+%h1
You are already Connected to
=params[:id].humanize
-form_tag oauth_consumer_path(params[:id]),:method=>:delete do
diff --git a/generators/oauth_provider/USAGE b/generators/oauth_provider/USAGE
index 94523cd3..de6910c7 100644
--- a/generators/oauth_provider/USAGE
+++ b/generators/oauth_provider/USAGE
@@ -1,4 +1,4 @@
-./script/generate oauth_provider
+./script/generate oauth_provider
This creates an OAuth Provider controller as well as the requisite models.
diff --git a/generators/oauth_provider/lib/insert_routes.rb b/generators/oauth_provider/lib/insert_routes.rb
index 6a8407c9..31f54dfc 100644
--- a/generators/oauth_provider/lib/insert_routes.rb
+++ b/generators/oauth_provider/lib/insert_routes.rb
@@ -3,7 +3,7 @@
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|
@@ -15,7 +15,7 @@ def route_entry(raw)
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|
@@ -23,10 +23,10 @@ def route_resource(*resources)
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|
@@ -35,7 +35,7 @@ def route_name(name, path, route_options = {})
end
end
end
-
+
Rails::Generator::Commands::Destroy.class_eval do
def route_resource(*resources)
resource_list = resources.map { |r| r.to_sym.inspect }.join(', ')
@@ -45,7 +45,7 @@ def route_resource(*resources)
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]}'"
@@ -54,13 +54,13 @@ def route_name(name, path, route_options = {})
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
diff --git a/generators/oauth_provider/oauth_provider_generator.rb b/generators/oauth_provider/oauth_provider_generator.rb
index a901934e..0f016eee 100644
--- a/generators/oauth_provider/oauth_provider_generator.rb
+++ b/generators/oauth_provider/oauth_provider_generator.rb
@@ -24,7 +24,7 @@ def initialize(runtime_args, runtime_options = {})
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
@@ -58,13 +58,13 @@ def manifest
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")
@@ -87,10 +87,10 @@ def manifest
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}")
@@ -100,7 +100,7 @@ def manifest
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"
@@ -117,11 +117,11 @@ def banner
def add_options!(opt)
opt.separator ''
opt.separator 'Options:'
- opt.on("--skip-migration",
+ opt.on("--skip-migration",
"Don't generate a migration file") { |v| options[:skip_migration] = v }
- opt.on("--test-unit",
+ opt.on("--test-unit",
"Generate the Test::Unit compatible tests instead of RSpec") { |v| options[:test_unit] = v }
- opt.on("--haml",
+ opt.on("--haml",
"Templates use haml") { |v| options[:haml] = v }
end
end
diff --git a/generators/oauth_provider/templates/_form.html.haml b/generators/oauth_provider/templates/_form.html.haml
index c8935860..7b3f8d3a 100644
--- a/generators/oauth_provider/templates/_form.html.haml
+++ b/generators/oauth_provider/templates/_form.html.haml
@@ -2,20 +2,20 @@
.field
%label{:for=>"client_application_name"} Name*
%br
- = f.text_field :name
+ = f.text_field :name
.field
%label{:for=>"client_application_url"} Main Application URL*
%br
- = f.text_field :url
+ = f.text_field :url
.field
%label{:for=>"client_application_callback_url"} Callback URL*
%br
- = f.text_field :callback_url
+ = f.text_field :callback_url
.field
%label{:for=>"client_application_support_url"} Support URL
%br
- = f.text_field :support_url
+ = f.text_field :support_url
diff --git a/generators/oauth_provider/templates/access_token.rb b/generators/oauth_provider/templates/access_token.rb
index bc2a9133..deef3049 100644
--- a/generators/oauth_provider/templates/access_token.rb
+++ b/generators/oauth_provider/templates/access_token.rb
@@ -1,15 +1,15 @@
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
-
+
+ protected
+
def set_authorized_at
self.authorized_at = Time.now
end
diff --git a/generators/oauth_provider/templates/client_application.rb b/generators/oauth_provider/templates/client_application.rb
index 7314ec8d..bada17f0 100644
--- a/generators/oauth_provider/templates/client_application.rb
+++ b/generators/oauth_provider/templates/client_application.rb
@@ -14,7 +14,7 @@ class ClientApplication < ActiveRecord::Base
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?
@@ -23,7 +23,7 @@ def self.find_token(token_key)
nil
end
end
-
+
def self.verify_request(request, options = {}, &block)
begin
signature = OAuth::Signature.build(request, options, &block)
@@ -34,22 +34,22 @@ def self.verify_request(request, options = {}, &block)
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={})
+ 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]
diff --git a/generators/oauth_provider/templates/client_application_spec.rb b/generators/oauth_provider/templates/client_application_spec.rb
index caaec258..06a9d25e 100644
--- a/generators/oauth_provider/templates/client_application_spec.rb
+++ b/generators/oauth_provider/templates/client_application_spec.rb
@@ -1,5 +1,5 @@
require File.dirname(__FILE__) + '/../spec_helper'
-describe ClientApplication do
+describe ClientApplication do
fixtures :users, :client_applications, :oauth_tokens
before(:each) do
@application = ClientApplication.create :name => "Agree2", :url => "http://agree2.com", :user => users(:quentin)
@@ -8,12 +8,12 @@
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
@@ -24,6 +24,6 @@
@application.credentials.key.should == @application.key
@application.credentials.secret.should == @application.secret
end
-
+
end
diff --git a/generators/oauth_provider/templates/client_application_test.rb b/generators/oauth_provider/templates/client_application_test.rb
index 3adf77c8..98e21392 100644
--- a/generators/oauth_provider/templates/client_application_test.rb
+++ b/generators/oauth_provider/templates/client_application_test.rb
@@ -1,19 +1,19 @@
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
@@ -22,12 +22,12 @@ def setup
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
@@ -38,5 +38,5 @@ def test_should_have_credentials
assert_equal @application.key, @application.credentials.key
assert_equal @application.secret, @application.credentials.secret
end
-
+
end
\ No newline at end of file
diff --git a/generators/oauth_provider/templates/clients_controller.rb b/generators/oauth_provider/templates/clients_controller.rb
index 1e495dc1..fbec94da 100644
--- a/generators/oauth_provider/templates/clients_controller.rb
+++ b/generators/oauth_provider/templates/clients_controller.rb
@@ -1,7 +1,7 @@
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'
@@ -20,13 +20,13 @@ def create
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"
@@ -41,7 +41,7 @@ def 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])
diff --git a/generators/oauth_provider/templates/clients_controller_spec.rb b/generators/oauth_provider/templates/clients_controller_spec.rb
index c719e8d7..782cabe1 100644
--- a/generators/oauth_provider/templates/clients_controller_spec.rb
+++ b/generators/oauth_provider/templates/clients_controller_spec.rb
@@ -5,32 +5,32 @@
describe OauthClientsController do
if defined?(Devise)
include Devise::TestHelpers
- end
+ 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')
@@ -42,71 +42,71 @@ def do_get
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
@@ -115,13 +115,13 @@ def do_valid_post
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')
@@ -129,26 +129,26 @@ def do_invalid_post
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
@@ -156,18 +156,18 @@ def do_valid_update
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')
diff --git a/generators/oauth_provider/templates/clients_controller_test.rb b/generators/oauth_provider/templates/clients_controller_test.rb
index eaa802d9..46e481ad 100644
--- a/generators/oauth_provider/templates/clients_controller_test.rb
+++ b/generators/oauth_provider/templates/clients_controller_test.rb
@@ -7,34 +7,34 @@ class OauthClientsController; def rescue_action(e) raise e end; end
class OauthClientsControllerIndexTest < ActionController::TestCase
include OAuthControllerTestHelper
tests OauthClientsController
-
- def setup
+
+ def setup
@controller = OauthClientsController.new
@request = ActionController::TestRequest.new
- @response = ActionController::TestResponse.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'
@@ -44,40 +44,40 @@ def test_should_render_index_template
class OauthClientsControllerShowTest < ActionController::TestCase
include OAuthControllerTestHelper
tests OauthClientsController
-
+
def setup
@controller = OauthClientsController.new
@request = ActionController::TestRequest.new
- @response = ActionController::TestResponse.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
@@ -87,86 +87,86 @@ class OauthClientsControllerNewTest < ActionController::TestCase
def setup
@controller = OauthClientsController.new
@request = ActionController::TestRequest.new
- @response = ActionController::TestResponse.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
+ @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
-
+ @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'}
@@ -176,46 +176,46 @@ 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)
@@ -226,13 +226,13 @@ 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
@@ -245,7 +245,7 @@ def setup
@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'}
@@ -255,24 +255,24 @@ 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')
diff --git a/generators/oauth_provider/templates/controller.rb b/generators/oauth_provider/templates/controller.rb
index 2d81f542..bee58eb4 100644
--- a/generators/oauth_provider/templates/controller.rb
+++ b/generators/oauth_provider/templates/controller.rb
@@ -1,14 +1,14 @@
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)
@@ -19,5 +19,5 @@ class OauthController < ApplicationController
# nil
# end
# end
-
+
end
diff --git a/generators/oauth_provider/templates/index.html.erb b/generators/oauth_provider/templates/index.html.erb
index 1024b3d4..96049833 100644
--- a/generators/oauth_provider/templates/index.html.erb
+++ b/generators/oauth_provider/templates/index.html.erb
@@ -16,7 +16,7 @@
<%% end %>
<%% end %>
-
+
<%% end %>
Application Developers
@@ -33,7 +33,7 @@
<%% @client_applications.each do |client|%>
<%% div_for client do %>
- <%%= link_to client.name, oauth_client_path(client) %>-
+ <%%= 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 %>
diff --git a/generators/oauth_provider/templates/index.html.haml b/generators/oauth_provider/templates/index.html.haml
index c9f00287..aaaf61e6 100644
--- a/generators/oauth_provider/templates/index.html.haml
+++ b/generators/oauth_provider/templates/index.html.haml
@@ -2,9 +2,9 @@
%h1 OAuth Client Applications
- unless @tokens.empty?
- %p
+ %p
The following tokens have been issued to applications in your name
-
+
%table
%tr
%th Application
diff --git a/generators/oauth_provider/templates/migration.rb b/generators/oauth_provider/templates/migration.rb
index a9dff580..00b4d9a2 100644
--- a/generators/oauth_provider/templates/migration.rb
+++ b/generators/oauth_provider/templates/migration.rb
@@ -12,7 +12,7 @@ def self.up
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
@@ -25,9 +25,9 @@ def self.up
t.timestamp :authorized_at, :invalidated_at, :valid_to
t.timestamps
end
-
+
add_index :oauth_tokens, :token, :unique => true
-
+
create_table :oauth_nonces do |t|
t.string :nonce
t.integer :timestamp
@@ -35,7 +35,7 @@ def self.up
t.timestamps
end
add_index :oauth_nonces,[:nonce, :timestamp], :unique
-
+
end
def self.down
diff --git a/generators/oauth_provider/templates/oauth2_authorize.html.erb b/generators/oauth_provider/templates/oauth2_authorize.html.erb
index f79b3e6b..a1c7ba51 100644
--- a/generators/oauth_provider/templates/oauth2_authorize.html.erb
+++ b/generators/oauth_provider/templates/oauth2_authorize.html.erb
@@ -6,7 +6,7 @@
<%%= 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
diff --git a/generators/oauth_provider/templates/oauth_nonce.rb b/generators/oauth_provider/templates/oauth_nonce.rb
index 075351b9..84211e31 100644
--- a/generators/oauth_provider/templates/oauth_nonce.rb
+++ b/generators/oauth_provider/templates/oauth_nonce.rb
@@ -3,7 +3,7 @@
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)
diff --git a/generators/oauth_provider/templates/oauth_nonce_spec.rb b/generators/oauth_provider/templates/oauth_nonce_spec.rb
index 7829bdc7..ed1f570e 100644
--- a/generators/oauth_provider/templates/oauth_nonce_spec.rb
+++ b/generators/oauth_provider/templates/oauth_nonce_spec.rb
@@ -9,15 +9,15 @@
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
diff --git a/generators/oauth_provider/templates/oauth_nonce_test.rb b/generators/oauth_provider/templates/oauth_nonce_test.rb
index 3c1a56ab..b273cc83 100644
--- a/generators/oauth_provider/templates/oauth_nonce_test.rb
+++ b/generators/oauth_provider/templates/oauth_nonce_test.rb
@@ -3,7 +3,7 @@
class ClientNoneTest < ActiveSupport::TestCase
include OAuth::Helper
-
+
def setup
@oauth_nonce = OauthNonce.remember(generate_key,Time.now.to_i)
end
@@ -11,15 +11,15 @@ def setup
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
diff --git a/generators/oauth_provider/templates/oauth_token.rb b/generators/oauth_provider/templates/oauth_token.rb
index a08a066b..2a1eae30 100644
--- a/generators/oauth_provider/templates/oauth_token.rb
+++ b/generators/oauth_provider/templates/oauth_token.rb
@@ -4,25 +4,25 @@ class OauthToken < ActiveRecord::Base
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]
diff --git a/generators/oauth_provider/templates/oauth_token_spec.rb b/generators/oauth_provider/templates/oauth_token_spec.rb
index 6f7d9ffc..b4adc08c 100644
--- a/generators/oauth_provider/templates/oauth_token_spec.rb
+++ b/generators/oauth_provider/templates/oauth_token_spec.rb
@@ -9,11 +9,11 @@
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
@@ -21,57 +21,57 @@
it "should have a secret" do
@token.secret.should_not be_nil
end
-
- it "should not be authorized" do
+
+ 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"
+ @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))
+ @token.authorize!(users(:quentin))
end
it "should be authorized" do
- @token.should be_authorized
+ @token.should be_authorized
end
it "should have authorized at" do
- @token.authorized_at.should_not be_nil
+ @token.authorized_at.should_not be_nil
end
it "should have user set" do
- @token.user.should == users(:quentin)
+ @token.user.should == users(:quentin)
end
it "should have verifier" do
- @token.verifier.should_not be_nil
+ @token.verifier.should_not be_nil
end
describe "exchange for access token" do
@@ -80,25 +80,25 @@
@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)
+ @access.user.should == users(:quentin)
end
-
+
it "should authorize accesstoken" do
- @access.should be_authorized
+ @access.should be_authorized
end
end
@@ -148,30 +148,30 @@
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))
+ @token.authorize!(users(:quentin))
end
it "should be authorized" do
- @token.should be_authorized
+ @token.should be_authorized
end
it "should have authorized at" do
- @token.authorized_at.should_not be_nil
+ @token.authorized_at.should_not be_nil
end
it "should have user set" do
- @token.user.should == users(:quentin)
+ @token.user.should == users(:quentin)
end
it "should have verifier" do
- @token.verifier.should_not be_nil
+ @token.verifier.should_not be_nil
end
describe "exchange for access token" do
@@ -186,11 +186,11 @@
end
it "should set user on access token" do
- @access.user.should == users(:quentin)
+ @access.user.should == users(:quentin)
end
it "should authorize accesstoken" do
- @access.should be_authorized
+ @access.should be_authorized
end
end
@@ -234,34 +234,34 @@
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))
+ @token.authorize!(users(:quentin))
end
it "should be authorized" do
- @token.should be_authorized
+ @token.should be_authorized
end
it "should have authorized at" do
- @token.authorized_at.should_not be_nil
+ @token.authorized_at.should_not be_nil
end
it "should have user set" do
- @token.user.should == users(:quentin)
+ @token.user.should == users(:quentin)
end
it "should not have verifier" do
- @token.verifier.should be_nil
+ @token.verifier.should be_nil
end
describe "exchange for access token" do
@@ -275,11 +275,11 @@
end
it "should set user on access token" do
- @access.user.should == users(:quentin)
+ @access.user.should == users(:quentin)
end
it "should authorize accesstoken" do
- @access.should be_authorized
+ @access.should be_authorized
end
end
diff --git a/generators/oauth_provider/templates/oauth_token_test.rb b/generators/oauth_provider/templates/oauth_token_test.rb
index dc7f5cb2..51d379e3 100644
--- a/generators/oauth_provider/templates/oauth_token_test.rb
+++ b/generators/oauth_provider/templates/oauth_token_test.rb
@@ -3,7 +3,7 @@
class RequestTokenTest < ActiveSupport::TestCase
fixtures :client_applications, :users, :oauth_tokens
-
+
def setup
@token = RequestToken.create :client_application=>client_applications(:one)
end
@@ -11,11 +11,11 @@ def setup
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
@@ -23,35 +23,35 @@ def test_should_have_a_token
def test_should_have_a_secret
assert_not_nil @token.secret
end
-
- def test_should_not_be_authorized
+
+ def test_should_not_be_authorized
assert !@token.authorized?
end
def test_should_not_be_invalidated
assert !@token.invalidated?
end
-
+
def test_should_authorize_request
@token.authorize!(users(:quentin))
assert @token.authorized?
assert_not_nil @token.authorized_at
assert_equal users(:quentin), @token.user
end
-
+
def test_should_not_exchange_without_approval
assert_equal false, @token.exchange!
assert_equal false, @token.invalidated?
end
-
+
def test_should_not_exchange_without_approval
@token.authorize!(users(:quentin))
@access = @token.exchange!
assert_not_equal false, @access
assert @token.invalidated?
-
+
assert_equal users(:quentin), @access.user
assert @access.authorized?
end
-
+
end
diff --git a/generators/oauth_provider/templates/request_token.rb b/generators/oauth_provider/templates/request_token.rb
index 75b8398e..a0b4f6bf 100644
--- a/generators/oauth_provider/templates/request_token.rb
+++ b/generators/oauth_provider/templates/request_token.rb
@@ -1,7 +1,7 @@
class RequestToken < OauthToken
-
+
attr_accessor :provided_oauth_verifier
-
+
def authorize!(user)
return false if authorized?
self.user = user
@@ -9,18 +9,18 @@ def authorize!(user)
self.verifier=OAuth::Helper.generate_key(20)[0,20] unless oauth10?
self.save
end
-
+
def exchange!
return false unless authorized?
return false unless oauth10? || verifier==provided_oauth_verifier
-
+
RequestToken.transaction do
access_token = AccessToken.create(:user => user, :client_application => client_application)
invalidate!
access_token
end
end
-
+
def to_query
if oauth10?
super
@@ -28,11 +28,11 @@ def to_query
"#{super}&oauth_callback_confirmed=true"
end
end
-
+
def oob?
callback_url.nil? || callback_url.downcase == 'oob'
end
-
+
def oauth10?
(defined? OAUTH_10_SUPPORT) && OAUTH_10_SUPPORT && self.callback_url.blank?
end
diff --git a/generators/oauth_provider/templates/show.html.haml b/generators/oauth_provider/templates/show.html.haml
index 1fca1750..a9d25188 100644
--- a/generators/oauth_provider/templates/show.html.haml
+++ b/generators/oauth_provider/templates/show.html.haml
@@ -1,12 +1,12 @@
-%h1
- OAuth details for
+%h1
+ OAuth details for
=@client_application.name
%p
%strong Consumer Key:
%code=@client_application.key
%p
%strong Consumer Secret:
- %code=@client_application.secret
+ %code=@client_application.secret
%p
%strong Request Token URL
diff --git a/init.rb b/init.rb
index 7bfb0043..26446634 100644
--- a/init.rb
+++ b/init.rb
@@ -1 +1 @@
-require File.dirname(__FILE__) + "/rails/init"
\ No newline at end of file
+require File.dirname(__FILE__) + "/rails/init"
\ No newline at end of file
diff --git a/lib/generators/active_record/oauth_consumer_templates/consumer_token.rb b/lib/generators/active_record/oauth_consumer_templates/consumer_token.rb
index e19663b4..12eaf2e6 100644
--- a/lib/generators/active_record/oauth_consumer_templates/consumer_token.rb
+++ b/lib/generators/active_record/oauth_consumer_templates/consumer_token.rb
@@ -1,11 +1,11 @@
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
\ No newline at end of file
diff --git a/lib/generators/active_record/oauth_consumer_templates/migration.rb b/lib/generators/active_record/oauth_consumer_templates/migration.rb
index afa3f6a3..310044ed 100644
--- a/lib/generators/active_record/oauth_consumer_templates/migration.rb
+++ b/lib/generators/active_record/oauth_consumer_templates/migration.rb
@@ -1,6 +1,6 @@
class CreateOauthConsumerTokens < ActiveRecord::Migration
def self.up
-
+
create_table :consumer_tokens do |t|
t.integer :user_id
t.string :type, :limit => 30
@@ -8,9 +8,9 @@ def self.up
t.string :secret
t.timestamps
end
-
+
add_index :consumer_tokens, :token, :unique => true
-
+
end
def self.down
diff --git a/lib/generators/active_record/oauth_provider_templates/request_token.rb b/lib/generators/active_record/oauth_provider_templates/request_token.rb
index c44f56f0..a0b4f6bf 100644
--- a/lib/generators/active_record/oauth_provider_templates/request_token.rb
+++ b/lib/generators/active_record/oauth_provider_templates/request_token.rb
@@ -28,7 +28,7 @@ def to_query
"#{super}&oauth_callback_confirmed=true"
end
end
-
+
def oob?
callback_url.nil? || callback_url.downcase == 'oob'
end
diff --git a/lib/generators/haml/oauth_consumer_templates/show.html.haml b/lib/generators/haml/oauth_consumer_templates/show.html.haml
index e7358b0b..cabe6d5d 100644
--- a/lib/generators/haml/oauth_consumer_templates/show.html.haml
+++ b/lib/generators/haml/oauth_consumer_templates/show.html.haml
@@ -1,4 +1,4 @@
-%h1
+%h1
You are already Connected to
=params[:id].humanize
-form_tag oauth_consumer_path(params[:id]),:method=>:delete do
diff --git a/lib/generators/mongoid/oauth_consumer_templates/consumer_token.rb b/lib/generators/mongoid/oauth_consumer_templates/consumer_token.rb
index 24128f9c..abe32bee 100644
--- a/lib/generators/mongoid/oauth_consumer_templates/consumer_token.rb
+++ b/lib/generators/mongoid/oauth_consumer_templates/consumer_token.rb
@@ -3,7 +3,7 @@ class ConsumerToken
include Mongoid::Document
include Mongoid::Timestamps
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
@@ -13,22 +13,22 @@ class ConsumerToken
index :token
# Add the following to your user model:
- #
- # embeds_many :consumer_tokens
+ #
+ # embeds_many :consumer_tokens
# index "consumer_tokens.token"
#
embedded_in :user, :inverse_of => :consumer_tokens
-
+
def self.find_or_create_from_access_token(user,access_token)
secret = access_token.respond_to?(:secret) ? access_token.secret : nil
-
+
if user
user.consumer_tokens.where(:_type=>self.to_s,:token=>access_token.token).first ||
self.create!(:_type=>self.to_s,:token=>access_token.token, :secret=>secret, :user=>user)
else
user = User.where("consumer_tokens._type"=>self.to_s,"consumer_tokens.token"=>access_token.token).first
if user
- user.consumer_tokens.detect{|t| t.token==access_token.token && t.is_a?(self)}
+ user.consumer_tokens.detect{|t| t.token==access_token.token && t.is_a?(self)}
else
user = User.new
self.create!(:_type=>self.to_s,:token=>access_token.token, :secret=>secret, :user=>user)
diff --git a/lib/generators/mongoid/oauth_provider_templates/request_token.rb b/lib/generators/mongoid/oauth_provider_templates/request_token.rb
index 8e630cf5..49d38cf4 100644
--- a/lib/generators/mongoid/oauth_provider_templates/request_token.rb
+++ b/lib/generators/mongoid/oauth_provider_templates/request_token.rb
@@ -25,7 +25,7 @@ def to_query
"#{super}&oauth_callback_confirmed=true"
end
end
-
+
def oob?
callback_url.nil? || callback_url.downcase == 'oob'
end
diff --git a/lib/generators/oauth_consumer/oauth_consumer_generator.rb b/lib/generators/oauth_consumer/oauth_consumer_generator.rb
index 4b382417..acd0a349 100644
--- a/lib/generators/oauth_consumer/oauth_consumer_generator.rb
+++ b/lib/generators/oauth_consumer/oauth_consumer_generator.rb
@@ -3,19 +3,19 @@
class OauthConsumerGenerator < Rails::Generators::Base
source_root File.expand_path("../templates", __FILE__)
-
+
hook_for :orm
-
+
def copy_models
template 'oauth_config.rb', File.join('config', 'initializers', 'oauth_consumers.rb')
end
-
+
def copy_controller
template 'controller.rb', File.join('app', 'controllers', 'oauth_consumers_controller.rb')
end
-
+
hook_for :template_engine
-
+
def add_route
route <<-ROUTE.strip
resources :oauth_consumers do
@@ -27,5 +27,5 @@ def add_route
end
ROUTE
end
-
+
end
diff --git a/lib/generators/oauth_consumer/templates/controller.rb b/lib/generators/oauth_consumer/templates/controller.rb
index 966bc58b..d77fad91 100644
--- a/lib/generators/oauth_consumer/templates/controller.rb
+++ b/lib/generators/oauth_consumer/templates/controller.rb
@@ -6,50 +6,50 @@ class OauthConsumersController < ApplicationController
#
# before_filter :authenticate_user!, :only=>:index
before_filter :login_required, :only=>:index
-
+
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
-
+
# The plugin requires logged_in? to return true or false if the user is logged in. Uncomment and
# call your auth frameworks equivalent below if different. eg. for devise:
#
# def logged_in?
# user_signed_in?
# end
-
+
# The plugin requires current_user to return the current logged in user. Uncomment and
# call your auth frameworks equivalent below if different.
# def current_user
# current_person
# end
- # The plugin requires a way to log a user in. Call your auth frameworks equivalent below
+ # The plugin requires a way to log a user in. Call your auth frameworks equivalent below
# if different. eg. for devise:
#
# def current_user=(user)
# sign_in(user)
# end
-
+
# Override this to deny the user or redirect to a login screen depending on your framework and app
# if different. eg. for devise:
#
diff --git a/lib/generators/oauth_consumer/templates/oauth_config.rb b/lib/generators/oauth_consumer/templates/oauth_config.rb
index 729aa0e3..a9a76ea4 100644
--- a/lib/generators/oauth_consumer/templates/oauth_config.rb
+++ b/lib/generators/oauth_consumer/templates/oauth_config.rb
@@ -53,15 +53,15 @@
# :nu_bux=>{
# :key=>"",
# :secret=>"",
-# :super_class=>"OpenTransactToken", # if a OAuth service follows a particular standard
+# :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"
+# :site=>"http://nubux.heroku.com"
# }
# }
# }
-#
+#
OAUTH_CREDENTIALS={
} unless defined? OAUTH_CREDENTIALS
diff --git a/lib/oauth/controllers/application_controller_methods.rb b/lib/oauth/controllers/application_controller_methods.rb
index 9991c696..4bceec7a 100644
--- a/lib/oauth/controllers/application_controller_methods.rb
+++ b/lib/oauth/controllers/application_controller_methods.rb
@@ -1,14 +1,14 @@
module OAuth
module Controllers
-
+
module ApplicationControllerMethods
-
+
def self.included(controller)
- controller.class_eval do
+ controller.class_eval do
extend ClassMethods
end
end
-
+
module ClassMethods
def oauthenticate(options={})
filter_options = {}
@@ -17,7 +17,7 @@ def oauthenticate(options={})
before_filter Filter.new(options), filter_options
end
end
-
+
class Filter
def initialize(options={})
@options={
@@ -27,19 +27,19 @@ def initialize(options={})
@strategies = Array(@options[:strategies])
@strategies << :interactive if @options[:interactive]
end
-
+
def filter(controller)
Authenticator.new(controller,@strategies).allow?
end
end
-
+
class Authenticator
attr_accessor :controller, :strategies, :strategy
def initialize(controller,strategies)
@controller = controller
@strategies = strategies
end
-
+
def allow?
if @strategies.include?(:interactive) && interactive
true
@@ -47,7 +47,7 @@ def allow?
@controller.send :current_user=, token.user if token
true
else
- if @strategies.include?(:interactive)
+ if @strategies.include?(:interactive)
controller.send :access_denied
else
controller.send :invalid_oauth_response
@@ -70,7 +70,7 @@ def oauth10_request_token
def oauth10_access_token
oauth10_token && oauth10_token.is_a?(::AccessToken) ? oauth10_token : nil
end
-
+
def token
oauth20_token || oauth10_access_token || nil
end
@@ -82,7 +82,7 @@ def client_application
def two_legged
env["oauth.version"]==1 && client_application
end
-
+
def interactive
@controller.send :logged_in?
end
@@ -96,36 +96,36 @@ def request
end
end
-
+
protected
-
+
def current_token
request.env["oauth.token"]
end
-
+
def current_client_application
request.env["oauth.version"]==1 && request.env["oauth.client_application"] || current_token.try(:client_application)
end
-
+
def oauth?
current_token
end
-
+
# use in a before_filter. Note this is for compatibility purposes. Better to use oauthenticate now
def oauth_required
Authenticator.new(self,[:oauth10_access_token]).allow?
end
-
+
# use in before_filter. Note this is for compatibility purposes. Better to use oauthenticate now
def login_or_oauth_required
Authenticator.new(self,[:oauth10_access_token,:interactive]).allow?
end
-
+
def invalid_oauth_response(code=401,message="Invalid OAuth Request")
render :text => message, :status => code
false
end
-
+
# override this in your controller
def access_denied
head 401
diff --git a/lib/oauth/controllers/consumer_controller.rb b/lib/oauth/controllers/consumer_controller.rb
index d084dcac..833203fe 100644
--- a/lib/oauth/controllers/consumer_controller.rb
+++ b/lib/oauth/controllers/consumer_controller.rb
@@ -2,18 +2,18 @@ module Oauth
module Controllers
module ConsumerController
def self.included(controller)
- controller.class_eval do
+ controller.class_eval do
before_filter :load_consumer, :except=>:index
skip_before_filter :verify_authenticity_token,:only=>:callback
end
end
-
+
def index
@consumer_tokens=ConsumerToken.all :conditions=>{:user_id=>current_user.id}
# The services the user hasn't already connected to
@services=OAUTH_CREDENTIALS.keys-@consumer_tokens.collect{|c| c.class.service_name}
- end
-
+ end
+
# creates request token and redirects on to oauth provider's auth page
# If user is already connected it displays a page with an option to disconnect and redo
def show
@@ -33,7 +33,7 @@ def show
end
end
end
-
+
def callback2
@token = @consumer.access_token(current_user,params[:code], callback2_oauth_consumer_url(params[:id]))
logger.info @token.inspect
@@ -42,7 +42,7 @@ def callback2
if logged_in?
flash[:notice] = "#{params[:id].humanize} was successfully connected to your account"
else
- self.current_user = @token.user
+ self.current_user = @token.user
flash[:notice] = "You logged in with #{params[:id].humanize}"
end
go_back
@@ -64,7 +64,7 @@ def callback
if logged_in?
flash[:notice] = "#{params[:id].humanize} was successfully connected to your account"
else
- self.current_user = @token.user
+ self.current_user = @token.user
flash[:notice] = "You logged in with #{params[:id].humanize}"
end
go_back
@@ -103,38 +103,38 @@ def destroy
redirect_to oauth_consumer_url(params[:id])
else
flash[:notice] = "#{params[:id].humanize} was successfully disconnected from your account"
-
+
go_back
end
end
protected
-
+
# Override this in your controller to decide where you want to redirect user to after callback is finished.
def go_back
redirect_to root_url
end
-
+
def consumer_credentials
OAUTH_CREDENTIALS[consumer_key]
end
-
+
def consumer_key
@consumer_key ||= params[:id].to_sym
end
-
+
def load_consumer
throw RecordNotFound unless OAUTH_CREDENTIALS.include?(consumer_key)
deny_access! unless logged_in? || consumer_credentials[:allow_login]
@consumer="#{consumer_key.to_s.camelcase}Token".constantize
@token=@consumer.find(:first, :conditions=>{:user_id=>current_user.id.to_s}) if logged_in?
end
-
+
# Override this in you controller to deny user or redirect to login screen.
def deny_access!
head 401
end
-
+
end
end
end
diff --git a/lib/oauth/models/consumers/service_loader.rb b/lib/oauth/models/consumers/service_loader.rb
index 8e792bf4..5bc7713c 100644
--- a/lib/oauth/models/consumers/service_loader.rb
+++ b/lib/oauth/models/consumers/service_loader.rb
@@ -3,7 +3,7 @@
# Goes through the entries in your OAUTH_CREDENTIALS and either loads the class required
# or subclasses ConsumerToken with the name.
#
-# So an entry called "my_service" will create a class MyServiceToken which you can
+# So an entry called "my_service" will create a class MyServiceToken which you can
# connect with has_one to your user model.
if defined? ConsumerToken && defined? OAUTH_CREDENTIALS
require File.join(File.dirname(__FILE__), 'services', 'oauth2_token')
diff --git a/lib/oauth/models/consumers/services/agree2_token.rb b/lib/oauth/models/consumers/services/agree2_token.rb
index ed18fcc8..cb604f88 100644
--- a/lib/oauth/models/consumers/services/agree2_token.rb
+++ b/lib/oauth/models/consumers/services/agree2_token.rb
@@ -4,11 +4,11 @@ class Agree2Token < ConsumerToken
def self.consumer
@consumer||=OAuth::Consumer.new credentials[:key],credentials[:secret],AGREE2_SETTINGS
end
-
+
def self.agree2_client
@agree2_client||=Agree2::Client.new credentials[:key],credentials[:secret]
end
-
+
def client
@client||=Agree2Token.agree2_client.user(token,secret)
end
diff --git a/lib/oauth/models/consumers/services/fireeagle_token.rb b/lib/oauth/models/consumers/services/fireeagle_token.rb
index b379f44d..0a772792 100644
--- a/lib/oauth/models/consumers/services/fireeagle_token.rb
+++ b/lib/oauth/models/consumers/services/fireeagle_token.rb
@@ -5,31 +5,31 @@ class FireeagleToken < ConsumerToken
FIREEAGLE_SETTINGS={
:site=>"https://fireeagle.yahooapis.com",
:authorize_url=>"https://fireeagle.yahoo.net/oauth/authorize"}
-
+
def self.consumer
@consumer||=OAuth::Consumer.new credentials[:key],credentials[:secret],FIREEAGLE_SETTINGS
end
-
+
def client
@client||=FireEagle::Client.new :consumer_key => FireeagleToken.consumer.key,
- :consumer_secret => FireeagleToken.consumer.secret,
- :access_token => token,
+ :consumer_secret => FireeagleToken.consumer.secret,
+ :access_token => token,
:access_token_secret => secret
end
-
+
# Returns the FireEagle User object
# http://fireeagle.rubyforge.org/classes/FireEagle/User.html
def fireeagle_user
@fireeagle_user||=client.user
end
-
+
# gives you the best guess of a location for user.
# This returns the FireEagle Location object:
# http://fireeagle.rubyforge.org/classes/FireEagle/Location.html
def location
fireeagle_user.best_guess.name
end
-
+
# Updates thes users location
# see: http://fireeagle.rubyforge.org/classes/FireEagle/Client.html#M000026
def update_location(location={})
diff --git a/lib/oauth/models/consumers/services/oauth2_token.rb b/lib/oauth/models/consumers/services/oauth2_token.rb
index cf1c0687..16ae6f6e 100644
--- a/lib/oauth/models/consumers/services/oauth2_token.rb
+++ b/lib/oauth/models/consumers/services/oauth2_token.rb
@@ -1,27 +1,27 @@
require 'oauth2'
class Oauth2Token < ConsumerToken
-
+
def self.consumer
@consumer||=create_consumer
- end
-
+ end
+
def self.create_consumer(options={})
@consumer||=OAuth2::Client.new credentials[:key],credentials[:secret],credentials[:options]
end
-
+
def self.authorize_url(callback_url)
options = {:redirect_uri=>callback_url}
options[:scope] = credentials[:scope] if credentials[:scope].present?
consumer.web_server.authorize_url(options)
end
-
+
def self.access_token(user, code, redirect_uri)
access_token = consumer.web_server.get_access_token(code, :redirect_uri => redirect_uri)
find_or_create_from_access_token user, access_token
end
-
+
def client
@client ||= OAuth2::AccessToken.new self.class.consumer, token
end
-
+
end
\ No newline at end of file
diff --git a/lib/oauth/models/consumers/services/opentransact_token.rb b/lib/oauth/models/consumers/services/opentransact_token.rb
index 6da3bb3e..9c7a1285 100644
--- a/lib/oauth/models/consumers/services/opentransact_token.rb
+++ b/lib/oauth/models/consumers/services/opentransact_token.rb
@@ -1,15 +1,15 @@
require 'opentransact'
class OpenTransactToken < ConsumerToken
-
+
# def self.server
# @consumer||=OpenTransact::Server.new credentials
# end
-
+
# def self.consumer
# @consumer||=server.consumer
# end
-
- def client
+
+ def client
@client ||= OpenTransact::Client.new self.class.credentials.merge( {:token=>token, :secret=>secret})
end
end
\ No newline at end of file
diff --git a/lib/oauth/models/consumers/services/picomoney_token.rb b/lib/oauth/models/consumers/services/picomoney_token.rb
index 7ecd447d..9d7af1b1 100644
--- a/lib/oauth/models/consumers/services/picomoney_token.rb
+++ b/lib/oauth/models/consumers/services/picomoney_token.rb
@@ -8,8 +8,8 @@ def self.credentials
:consumer_key => super[:key],
:consumer_secret => super[:secret]
}.merge(super)
- end
-
+ end
+
def about_user
client.get("/about_user")
end
diff --git a/lib/oauth/models/consumers/services/twitter_token.rb b/lib/oauth/models/consumers/services/twitter_token.rb
index 90238ece..011bafa2 100644
--- a/lib/oauth/models/consumers/services/twitter_token.rb
+++ b/lib/oauth/models/consumers/services/twitter_token.rb
@@ -5,14 +5,14 @@ class TwitterToken < ConsumerToken
:authorize_path => "/oauth/authorize",
:access_token_path => "/oauth/access_token",
}
-
+
def self.consumer(options={})
@consumer ||= OAuth::Consumer.new(credentials[:key], credentials[:secret], TWITTER_SETTINGS.merge(options))
end
-
+
def client
- @client ||= begin
- if credentials[:client].to_sym==:oauth_gem
+ @client ||= begin
+ if credentials[:client].to_sym==:oauth_gem
super
else
require 'twitter'
@@ -20,5 +20,5 @@ def client
end
end
end
-
+
end
diff --git a/lib/oauth/models/consumers/simple_client.rb b/lib/oauth/models/consumers/simple_client.rb
index 80756676..15f2994b 100644
--- a/lib/oauth/models/consumers/simple_client.rb
+++ b/lib/oauth/models/consumers/simple_client.rb
@@ -5,12 +5,12 @@ module Consumers
# This is just a simple
class SimpleClient
attr_reader :token
-
+
def initialize(token)
@token = token
end
-
-
+
+
def put(path,params={})
parse(token.put(path,params, {'Accept' => 'application/json'}))
end
@@ -41,9 +41,9 @@ def parse(response)
logger.debug "Got Response code: #{response.code}"
false
end
-
+
end
-
+
end
end
end
diff --git a/lib/oauth/models/consumers/token.rb b/lib/oauth/models/consumers/token.rb
index 93a12df2..fd79a194 100644
--- a/lib/oauth/models/consumers/token.rb
+++ b/lib/oauth/models/consumers/token.rb
@@ -14,13 +14,13 @@ def self.included(model)
model.send(:extend, ClassMethods)
end
-
+
module ClassMethods
-
+
def service_name
@service_name||=self.to_s.underscore.scan(/^(.*?)(_token)?$/)[0][0].to_sym
end
-
+
def consumer
options = credentials[:options] || {}
@consumer||=OAuth::Consumer.new credentials[:key],credentials[:secret],options
@@ -37,7 +37,7 @@ def find_or_create_from_request_token(user,token,secret,oauth_verifier)
access_token=request_token.get_access_token options
find_or_create_from_access_token user, access_token
end
-
+
def find_or_create_from_access_token(user,access_token)
secret = access_token.respond_to?(:secret) ? access_token.secret : nil
if user
@@ -45,26 +45,26 @@ def find_or_create_from_access_token(user,access_token)
else
token = self.find_or_initialize_by_token(access_token.token)
end
-
+
# set or update the secret
token.secret = secret
token.save! if token.new_record? or token.changed?
token
end
-
+
def build_user_from_token
end
protected
-
+
def credentials
@credentials||=OAUTH_CREDENTIALS[service_name]
end
-
+
end
-
+
module InstanceMethods
-
+
# Main client for interfacing with remote service. Override this to use
# preexisting library eg. Twitter gem.
def client
@@ -74,19 +74,19 @@ def client
def simple_client
@simple_client||=SimpleClient.new client
end
-
+
# Override this to return user data from service
def params_for_user
{}
end
-
+
def create_user
self.user ||= begin
User.new params_for_user
user.save(:validate=>false)
end
- end
-
+ end
+
end
end
end