Skip to content

Commit

Permalink
Merge remote branch 'upstream/master'
Browse files Browse the repository at this point in the history
  • Loading branch information
Brad Harrell committed May 2, 2012
2 parents 9b806f1 + f4d4f10 commit f77ec7d
Show file tree
Hide file tree
Showing 59 changed files with 391 additions and 373 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG
@@ -1,3 +1,10 @@
0.4.0
- fix migrations to use expires_at instead of valid_to [pelle]
- add force parameter for forcing token refresh [afeld]
- make it work in rails 2x [Kimtaro]
- Use 0.5+ OAuth2 gem [kookster]
- prevent addition of ? marks to callback url when not needed [kookster]
- make .credentials accessible to TwitterToken [afeld]
0.4.0-rc2
- Better OAuth2 support.
- Refactored authorizer into a Authorizer object which is now better tested
Expand Down
2 changes: 1 addition & 1 deletion README.rdoc
Expand Up @@ -92,7 +92,7 @@ You need to install the oauth gem (0.4.4) which is the core OAuth ruby library.

Add the plugin to your Gemfile:

gem "oauth-plugin", ">= 0.4.0.pre1"
gem "oauth-plugin", "~> 0.4.0"

And install it:

Expand Down
2 changes: 1 addition & 1 deletion 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:
Expand Down
18 changes: 9 additions & 9 deletions generators/oauth_consumer/oauth_consumer_generator.rb
Expand Up @@ -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"
Expand All @@ -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
6 changes: 3 additions & 3 deletions 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
10 changes: 5 additions & 5 deletions generators/oauth_consumer/templates/controller.rb
@@ -1,27 +1,27 @@
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
6 changes: 3 additions & 3 deletions generators/oauth_consumer/templates/migration.rb
@@ -1,16 +1,16 @@
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

end

def self.down
Expand Down
6 changes: 3 additions & 3 deletions generators/oauth_consumer/templates/oauth_config.rb
Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion 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
Expand Down
2 changes: 1 addition & 1 deletion 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.

Expand Down
16 changes: 8 additions & 8 deletions generators/oauth_provider/lib/insert_routes.rb
Expand Up @@ -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|
Expand All @@ -15,18 +15,18 @@ 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|
"#{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|
Expand All @@ -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(', ')
Expand All @@ -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]}'"
Expand All @@ -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
Expand Down
20 changes: 10 additions & 10 deletions generators/oauth_provider/oauth_provider_generator.rb
Expand Up @@ -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
Expand Down Expand Up @@ -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")
Expand All @@ -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}")
Expand All @@ -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"
Expand All @@ -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
8 changes: 4 additions & 4 deletions generators/oauth_provider/templates/_form.html.haml
Expand Up @@ -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

8 changes: 4 additions & 4 deletions 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
Expand Down
16 changes: 8 additions & 8 deletions generators/oauth_provider/templates/client_application.rb
Expand Up @@ -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?
Expand All @@ -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)
Expand All @@ -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]
Expand Down

0 comments on commit f77ec7d

Please sign in to comment.