Giter Site home page Giter Site logo

oauth-plugin's Introduction

OAuth Plugin

This is a plugin for implementing OAuth Providers and Consumers in Rails applications.

We support the revised OAuth 1.0a specs at:

tools.ietf.org/html/rfc5849

As well as support for OAuth 2.0:

tools.ietf.org/html/draft-ietf-oauth-v2-22

Find out more on the OAuth site at:

oauth.net

IMPORTANT note for people upgrading the provider

There are several changes to the latest OAuth 2.0 spec which requires a couple of changes to 2 models which you are REQUIRED to update manually if you are supporting OAuth2.

github.com/pelle/oauth-plugin/blob/master/lib/generators/active_record/oauth_provider_templates/oauth2_token.rb

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

github.com/pelle/oauth-plugin/blob/master/lib/generators/active_record/oauth_provider_templates/oauth2_verifier.rb

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

There are matching specs for these which you may want to move into your project as well.

Requirements

You need to install the oauth gem (0.4.4) which is the core OAuth ruby library. It will likely NOT work on any previous version of the gem.

gem install oauth

Installation (Rails 3.0)

Add the plugin to your Gemfile:

gem "oauth-plugin", "~> 0.4.0"

And install it:

bundle install

Installation (Rails 2.x)

The plugin can now be installed as an gem from github, which is the easiest way to keep it up to date.

gem install oauth-plugin --pre

You should add the following in the gem dependency section of environment.rb

config.gem "oauth"
config.gem "oauth-plugin"

Alternatively you can install it in vendors/plugin:

script/plugin install git://github.com/pelle/oauth-plugin.git

The Generator currently creates code (in particular views) that only work in Rails 2 and 3.

It should not be difficult to manually modify the code to work on Rails 1.2.x

I think the only real issue is that the views have .html.erb extensions. So these could theoretically just be renamed to .rhtml.

Please let me know if this works and I will see if I can make the generator conditionally create .rhtml for pre 2.0 versions of RAILS.

OAuth Provider generator (Rails 3)

This currently supports rspec, test_unit, haml, erb, active_record and mongoid:

rails g oauth_provider

This generates OAuth and OAuth client controllers as well as the required models.

It requires an authentication framework such as acts_as_authenticated, restful_authentication or restful_open_id_authentication. It also requires Rails 2.0.

INSTALL RACK FILTER (NEW)

A big change over previous versions is that we now use a rack filter. You have to install this in your application.rb file:

require 'oauth/rack/oauth_filter'
config.middleware.use OAuth::Rack::OAuthFilter

Generator Options

The generator supports the defaults you have created in your application.rb file. eg:

config.generators do |g|
  g.orm             :mongoid
  g.template_engine :haml
  g.test_framework  :rspec
end

User Model

Add the following lines to your user model:

has_many :client_applications
has_many :tokens, :class_name => "OauthToken", :order => "authorized_at desc", :include => [:client_application]

OAuth Provider generator (Rails 2)

While it isn’t very flexible at the moment there is an oauth_provider generator which you can use like this:

./script/generate oauth_provider

This generates OAuth and OAuth client controllers as well as the required models.

It requires an authentication framework such as acts_as_authenticated, restful_authentication or restful_open_id_authentication. It also requires Rails 2.0.

INSTALL RACK FILTER (NEW)

A big change over previous versions is that we now use a rack filter. You have to install this in your config/environment.rb file:

require 'oauth/rack/oauth_filter'
config.middleware.use OAuth::Rack::OAuthFilter

Generator Options

By default the generator generates RSpec and ERB templates. The generator can instead create Test::Unit and/or HAML templates. To do this use the following options:

./script/generate oauth_provider --test-unit --haml

These can of course be used individually as well.

User Model

Add the following lines to your user model:

has_many :client_applications
has_many :tokens, :class_name => "OauthToken", :order => "authorized_at desc", :include => [:client_application]

Migrate database

The database is defined in:

db/migrate/XXX_create_oauth_tables.rb

Run them as any other normal migration in rails with:

rake db:migrate

Upgrading from OAuth 1.0 to OAuth 1.0a

As the flow has changed slightly and there are a couple of database changes it isn’t as simple as just updating the plugin. Please follow these steps closely:

Add a migration

You need to add a migration:

script/generate migration upgrade_oauth

Make it look like this:

class UpgradeOauth < ActiveRecord::Migration
  def self.up
    add_column :oauth_tokens, :callback_url, :string
    add_column :oauth_tokens, :verifier, :string, :limit => 20
  end

  def self.down
    remove_column :oauth_tokens, :callback_url
    remove_column :oauth_tokens, :verifier
  end
end

Change code

There are changes to the following files:

app/models/client_application.rb
app/models/request_token.rb
app/controllers/oauth_controller.rb

Changes in client_application.rb

Add the following towards the top of the model class

attr_accessor :token_callback_url

Then change the create_request_token method to the following:

def create_request_token
  RequestToken.create :client_application => self, :callback_url => token_callback_url
end

Changes in request_token.rb

The RequestToken contains the bulk of the changes so it’s easiest to list it in it’s entirety. Mainly we need to add support for the oauth_verifier parameter and also tell the client that we support OAuth 1.0a.

Make sure it looks like this:

class RequestToken < OauthToken

  attr_accessor :provided_oauth_verifier

  def authorize!(user)
    return false if authorized?
    self.user = user
    self.authorized_at = Time.now
    self.verifier=OAuth::Helper.generate_key(16)[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
    else
      "#{super}&oauth_callback_confirmed = true"
    end
  end

  def oob?
    self.callback_url == 'oob'
  end

  def oauth10?
    (defined? OAUTH_10_SUPPORT) && OAUTH_10_SUPPORT && self.callback_url.blank?
  end

end

Changes in oauth_controller

All you need to do here is the change the authorize action to use the request_token callback url and add the oauth_verifier to the callback url.

def authorize
  @token = ::RequestToken.find_by_token params[:oauth_token]
  unless @token.invalidated?
    if request.post?
      if params[:authorize] == '1'
        @token.authorize!(current_user)
        if @token.oauth10?
          @redirect_url = params[:oauth_callback] || @token.client_application.callback_url
        else
          @redirect_url = @token.oob? ? @token.client_application.callback_url : @token.callback_url
        end

        if @redirect_url
          if @token.oauth10?
            redirect_to "#{@redirect_url}?oauth_token=#{@token.token}"
          else
            redirect_to "#{@redirect_url}?oauth_token=#{@token.token}&oauth_verifier=#{@token.verifier}"
          end
        else
          render :action => "authorize_success"
        end
      elsif params[:authorize] == "0"
        @token.invalidate!
        render :action => "authorize_failure"
      end
    end
  else
    render :action => "authorize_failure"
  end
end

Alternatively if you haven’t customized your controller you can replace the full controller with this:

require 'oauth/controllers/provider_controller'
class OauthController < ApplicationController
  include OAuth::Controllers::ProviderController
end

This way the controller will automatically include bug fixes in future versions of the plugin.

The rest of the changes are in the plugin and will be automatically be included.

Note OAuth 1.0a removes support for callback url’s passed to the authorize page, clients must either define a callback url in their client application or pass one on the token request page.

Supporting old OAuth 1.0 clients

If you absolutely have to support older OAuth 1.0 clients on an optional basis, we now include a switch to turn it back on.

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.

Protecting your actions

I recommend that you think about what your users would want to provide access to and limit oauth for those only. For example in a CRUD controller you may think about if you want to let consumer applications do the create, update or delete actions. For your application this might make sense, but for others maybe not.

If you want to give oauth access to everything a registered user can do, just replace the filter you have in your controllers with:

before_filter :login_or_oauth_required

If you want to restrict consumers to the index and show methods of your controller do the following:

before_filter :login_required, :except => [:show,:index]
before_filter :login_or_oauth_required, :only => [:show,:index]

If you have an action you only want used via oauth:

before_filter :oauth_required

You can also use this method in your controller:

oauthenticate :strategies => :token , :interactive => false

All of these places the tokens user in current_user as you would expect. It also exposes the following methods:

  • current_token - for accessing the token used to authorize the current request

  • current_client_application - for accessing information about which consumer is currently accessing your request

You could add application specific information to the OauthToken and ClientApplication model for such things as object level access control, billing, expiry etc. Be creative and you can create some really cool applications here.

OAuth Consumer generator

The oauth_consumer generator creates a controller to manage the authentication flow between your application and any number of external OAuth secured applications that you wish to connect to.

To run it in Rails 3 simply run:

rails g oauth_consumer

In previous versions:

./script/generate oauth_consumer

This generates the OauthConsumerController as well as the ConsumerToken model.

Generator Options (Rails 2)

By default the generator generates ERB templates. The generator can instead create HAML templates. To do this use the following options:

./script/generate oauth_consumer --haml

Rails 3 respects your application defaults, see the oauth provider generator section above for more info.

Configuration

All configuration of applications is done in

config/initializers/oauth_consumers.rb

Add entries to OAUTH_CREDENTIALS for all OAuth Applications you wish to connect to. Get this information by registering your application at the particular applications developer page.

OAUTH_CREDENTIALS = {
  :twitter => {
    :key => "key",
    :secret => "secret",
    :client => :twitter_gem, # :twitter_gem or :oauth_gem (defaults to :twitter_gem)
    :expose => false, # set to true to expose client via the web
  },
  :agree2 => {
    :key => "key",
    :secret => "secret",
    :expose => false, # set to true to expose client via the web
  },
  :hour_feed => {
    :key => "",
    :secret => "",
    :options = {
      :site => "http://hourfeed.com"
    }
  },
  :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 => {
      :site => "http://nubux.heroku.com"
    }
  }
}

You can add any of the options that the OAuth::Consumer.new accepts to the options hash: oauth.rubyforge.org/rdoc/classes/OAuth/Consumer.html

:key, :secret are required as well as :options etc. for non custom ConsumerToken services.

ConsumerToken models

For each site setup in the OAUTH_CREDENTIALS hash the plugin goes through and loads or creates a new model class that subclasses ConsumerToken.

eg. If you connect to Yahoo’s FireEagle you would add the :fire_eagle entry to OAUTH_CREDENTIALS and a new FireEagleToken model class will be created on the fly.

This allows you to add a has_one association in your user model:

has_one  :fire_eagle, :class_name => "FireEagleToken", :dependent => :destroy

And you could do:

@location = @user.fire_eagle.client.location

The client method gives you a OAuth::AccessToken which you can use to perform rest operations on the client site - see oauth.rubyforge.org/rdoc/classes/OAuth/AccessToken.html

If you are using Mongoid you want to add an embeds_many association in your user model:

embeds_many :consumer_tokens

Custom ConsumerToken models

Before creating the FireEagleToken model the plugin checks if a class already exists by that name or if we provide an api wrapper for it. This allows you to create a better token model that uses an existing ruby gem.

Currently we provide the following semi tested tokens wrappers:

  • FireEagle

  • Twitter

  • Agree2

These can be found in lib/oauth/models/consulers/services. Contributions will be warmly accepted for your favorite OAuth service.

The OauthConsumerController

To connect a user to an external service link or redirect them to:

/oauth_consumers/[SERVICE_NAME]

Where SERVICE_NAME is the name you set in the OAUTH_CREDENTIALS hash. This will request the request token and redirect the user to the services authorization screen. When the user accepts the get redirected back to:

/oauth_consumers/[SERVICE_NAME]/callback

You can specify this url to the service you’re calling when you register, but it will automatically be sent along anyway.

Expose client

This is designed to let your local javascript apps access remote OAuth apis. You have to specifically enable this by adding the expose flag to your oauth config file. eg:

OAUTH_CREDENTIALS = {
  :twitter => {
    :key => "key",
    :secret => "secret",
    :client => :oauth_gem, # :twitter_gem or :oauth_gem (defaults to :twitter_gem)
    :expose => true      # set to true to expose client via the web
  }

Once the user has authorized your application, you can access the client APIs via:

/oauth_consumers/[SERVICE_NAME]/client/[ENDPOINT]

For example to get the user’s Google Calendars in JSON (documented in their API as “www.google.com/calendar/feeds/default?alt=jsonc”), you would append that path as the ENDPOINT above, i.e.

/oauth_consumers/google/client/calendar/feeds/default?alt=jsonc

As another example, to get my Twitter info as XML (available at “api.twitter.com/1/users/show.xml?screen_name=pelleb”), use:

/oauth_consumers/twitter/client/1/users/show.xml?screen_name=pelleb

Migrate database

The database is defined in:

db/migrate/XXX_create_oauth_consumer_tokens.rb

Run them as any other normal migration in rails with:

rake db:migrate

Contribute and earn OAuth Karma

Anyone who has a commit accepted into the official oauth-plugin git repo is awarded OAuthKarma:

picomoney.com/oauth-karma/accounts

More

The Mailing List for all things OAuth in Ruby is:

groups.google.com/group/oauth-ruby

The Mailing list for everything else OAuth is:

groups.google.com/group/oauth

The OAuth Ruby Gem home page is oauth.rubyforge.org

Please help documentation, patches and testing.

Copyright © 2007-2011 Pelle Braendgaard and contributors, released under the MIT license

oauth-plugin's People

Contributors

3en avatar afeld avatar aflatter avatar akonan avatar alec-c4 avatar alsemyonov avatar cqr avatar filiptepper avatar haruska avatar hoblin avatar igrigorik avatar ivanku avatar ivanvc avatar jcrosby avatar jimsynz avatar jordimassaguerpla avatar kentonwhite avatar kimtaro avatar kookster avatar krasio avatar marnen avatar nifuramu avatar nov avatar p8 avatar pelle avatar shaliko avatar tessro avatar theirix avatar thetizzo avatar tomhughes avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

oauth-plugin's Issues

CreateOauthTables migration buggy

When running ./script/generate oauth_provider a migration for nessecary tables is generated. The indexes that are created should be uniqe
add_index :client_applications, :key, :unique

Correct Syntax is:
add_index :client_applications, :key, :unique => true

Consumer Issue with versions >= 0.4.0 pre-3 (Mongoid)

I noticed this issue appears in 0.4.0 pre-3 and in 0.4.0 pre-4 with Mongoid. For debugging purposes I am using 0.4.0 pre-4.

I destroyed and re-generated oauth_consumer

The following error occurs even with the newly generated oauth_consumer_controller:

Unknown action
The action 'callback' could not be found for OauthConsumersController

If I add (to oauth_consumer_controller):

def callback
    super
end

The error results in:

can't convert Hash into Integer

app/models/consumer_token.rb:26:in `find_or_create_from_access_token'
app/controllers/oauth_consumers_controller.rb:16:in `callback'

Also just to double check as I belive this is not documented anywhere but looking at the generated ConsumerToken model I have defined the Mongoid relationship in User as "embeds_many :consumer_tokens". I believe this is right.

Any idea what's causing this. I believe it's only a problem since 0.4.0 pre-3

Cohabitating oauth-plugin with authlogic-connect yields naming conflicts

I've got a site which uses the authlogic-connect gem for Facebook/Twitter OAuth authentication. When I run the ouath-plugin generator, I get this:

$ >> rails g oauth_provider
      invoke  active_record
The name 'AccessToken' is either already used in your application or reserved by Ruby on Rails. Please choose an alternative and run this generator again.

I wouldn't take issue with renaming AccessToken, but unfortunately that model is buried within the authlogic-connect gem.

Perhaps we could parameterize the AccessToken class name in the generator?

no routes defined by the generators

Hi,

I get no routes defined after running the generators (for both consumer/producer).
Even if I define the basic routes for my oauth_consumers_controller the named routes of the lib/oauth/controllers/consumer_controller (and the rest of course) remain undefined.

I'm using ruby 1.8.7 MRI and rails 3.0.4.

Any ideas what the problem might be?

TypeError when finding oauth token(Mongoid)

When requesting a request token, i get an error:
TypeError (can't convert Hash into Integer):
app/models/client_application.rb:48:in `verify_request'
I backtraced in and figured out that the error is from oauth/rack/oauth_filter.rb:31
oauth_token = client_application.tokens.first(:conditions=>{:token => request_proxy.token})
I think it should be something like this:
oauth_token = client_application.tokens.where(:conditions=>{:token => request_proxy.token}).first

Rspec Testing 160 Routing Errors

Oauthorized Controller is the routing errors and it has to do with uncommenting 1 line in your routes.rb file
Make sure the following is at the end of the routes.rb file
match ':controller(/:action(/:id(.:format)))'

This is legacy but will make the tests pass. Now i have 5 more errors to resolve on the rspec tests with rails 3.

Rails lazy class loading and defined?(Oauth2Token)

Hi,
when setting up oauthentication with your plugin i stumbled across Rails lazy Class loading. In your application_controller_methods is the following method:

def oauth20_token
return false unless defined?(Oauth2Token)
[...]

When the class was not loaded yet, this method returns and tells the client OAuth failed.
If i log
RAILS_DEFAULT_LOGGER.debug(defined?(Oauth2Token))
RAILS_DEFAULT_LOGGER.debug(Oauth2Token)
RAILS_DEFAULT_LOGGER.debug(defined?(Oauth2Token))
the class gets autoloaded (of course) and OAuth works as expected both on the server and client.

My question is: is the only workaround to eager load or require the Oauth2Token-Class? Or is this supposed to work otherwise?

Thanks again in advance for your help

No such file to load, uninitialized constant

Hi,

Many thanks for your working around oauth.

I was realy excited to use this gem but I had 2 major problem for using the oauth consumer.

  1. (resolved) It's write anywhere in doc that the rails generate commande line should have a additional argument to working, otherwise this error occurs and stop process

    C:\oauth_plugin>rails g oauth_consumer
      invoke  active_record
      create    app/models/consumer_token.rb
      create    db/migrate/20101214142735_create_oauth_consumer_tokens.rb
      create  config/initializers/oauth_consumers.rb
      create  app/controllers/oauth_consumers_controller.rb
      invoke  erb
    No value provided for required arguments 'name'
    

    Change "rails g oauth_consumer" to "rails g oauth_consumer oauth" to avoid errror. (I don't know where this arguement is used ??!? ).

  2. An then, when I have setup my oauth controller, oauth model and OAUTH_CREDENTIALS. I have the following error on url http://127.0.0.1:3000/oauth_consumers/

    LoadError in Oauth consumersController#index
    
    

no such file to load -- json

And when I'm going to http://127.0.0.1:3000/oauth_consumers/google :

NameError in Oauth consumersController#show

uninitialized constant GoogleToken

I'm a forum explorer rather than ruby senior developper, So I didn't found any post about this problem relative to oauth_plugin. Can you please help me ?

My config:
Windows 7
ruby 1.8.7
rails 3.0.3
oauth 0.4.4
oauth-plugin 0.4.0.pre3

views and routes not getting created on generate oauth_provider

It seems that when i run rails g oauth_provider i get the following:

$ /usr/local/bin/rails g oauth_provider
invoke mongoid
create app/models/client_application.rb
create app/models/oauth_token.rb
create app/models/request_token.rb
create app/models/access_token.rb
create app/models/oauth2_token.rb
create app/models/oauth2_verifier.rb
create app/models/oauth_nonce.rb
create app/controllers/oauth_controller.rb
create app/controllers/oauth_clients_controller.rb
invoke test_unit
create test/oauth_controller_test_helper.rb
create test/functional/oauth_controller_test.rb
create test/functional/oauth_clients_controller_test.rb
create test/unit/client_application_test.rb
create test/unit/oauth_token_test.rb
create test/unit/oauth_nonce_test.rb
invoke erb
No value provided for required arguments 'name'

but it seems to skip generation of the views and routes that it seems should be created when i look at the generator https://github.com/pelle/oauth-plugin/blob/rails3/generators/oauth_provider/oauth_provider_generator.rb

here is the relevent info from my gem file:
gem 'rails', '3.0.4'
gem 'mongoid', '2.0.0.beta.20'
gem 'bson_ext', '>= 1.2.1'
gem 'devise', '1.1.3'
gem 'oauth', :git => "http://github.com/pelle/oauth.git", :require => 'oauth/server'
gem "oauth-plugin", :git => 'https://github.com/pelle/oauth-plugin.git', :branch => 'rails3'

Any ideas?

retrieving credentials from ConsumerToken

So inside of the TwitterToken#client method, I am getting the follow error when trying to authorize:

undefined local variable or method `credentials' for #<TwitterToken:0x420ce6ac>

I threw in some debugger statements and was strangely able to access credentials from within TwitterToken.consumer - i.e. only from the class but not from the instance. Any idea how I might get around this? I tried self.class.credentials, but no dice.

Ruby 1.9.1. issue

I get this error in ruby 1.9.1 calling out to an authentication url. This works in ruby 1.8.7

TypeError in Oauth consumersController#show

can't dup Symbol

RAILS_ROOT: C:/sites/bizii
Application Trace | Framework Trace | Full Trace

C:/Ruby19/lib/ruby/1.9.1/net/http.rb:1529:in dup' C:/Ruby19/lib/ruby/1.9.1/net/http.rb:1529:inurlencode'
C:/Ruby19/lib/ruby/1.9.1/net/http.rb:1524:in block in encode_kvpair' C:/Ruby19/lib/ruby/1.9.1/net/http.rb:1524:inmap'
C:/Ruby19/lib/ruby/1.9.1/net/http.rb:1524:in encode_kvpair' C:/Ruby19/lib/ruby/1.9.1/net/http.rb:1517:inblock in set_form_data'
C:/Ruby19/lib/ruby/1.9.1/net/http.rb:1517:in each' C:/Ruby19/lib/ruby/1.9.1/net/http.rb:1517:inmap'
C:/Ruby19/lib/ruby/1.9.1/net/http.rb:1517:in set_form_data' C:/Ruby19/lib/ruby/gems/1.9.1/gems/oauth-0.3.6/lib/oauth/consumer.rb:324:increate_http_request'
C:/Ruby19/lib/ruby/gems/1.9.1/gems/oauth-0.3.6/lib/oauth/consumer.rb:176:in create_signed_request' C:/Ruby19/lib/ruby/gems/1.9.1/gems/oauth-0.3.6/lib/oauth/consumer.rb:149:inrequest'
C:/Ruby19/lib/ruby/gems/1.9.1/gems/oauth-0.3.6/lib/oauth/consumer.rb:183:in token_request' C:/Ruby19/lib/ruby/gems/1.9.1/gems/oauth-0.3.6/lib/oauth/consumer.rb:128:inget_request_token'

RecordNotFound is undefined

When I try to disconnect a user who is already disconnected from an oauth service I get the following:

uninitialized constant Oauth::Controllers::ConsumerController::RecordNotFound
/usr/lib/ruby/gems/1.8/gems/activesupport-2.3.8/lib/active_support/dependencies.rb:440:in load_missing_constant' /usr/lib/ruby/gems/1.8/gems/activesupport-2.3.8/lib/active_support/dependencies.rb:80:inconst_missing'
/myapp/vendor/plugins/oauth-plugin/lib/oauth/controllers/consumer_controller.rb:49:in `destroy'

Model Name Change No Affect

Hi

I've changed my model name from user to page, ran the migration and oauth-plugin is still executing for user model...

The error it throws is as follows"

SQLite3::SQLException: no such column: consumer_tokens.user_id: SELECT "consumer_tokens".* FROM "consumer_tokens" WHERE "consumer_tokens"."type" = 'TwitterToken' AND "consumer_tokens"."user_id" = '1' LIMIT 1

Can anyone assist with this?

Simon

Name required in generator

Basically all of the examples give the syntax as "rails g oauth_provider", but this gives an error and never produces views:

rails g oauth_provider
      invoke  active_record
      create    app/models/client_application.rb
      create    app/models/oauth_token.rb
      create    app/models/request_token.rb
      create    app/models/access_token.rb
      create    app/models/oauth2_token.rb
      create    app/models/oauth2_verifier.rb
      create    app/models/oauth_nonce.rb
      create    db/migrate/20110210222633_create_oauth_tables.rb
      create  app/controllers/oauth_controller.rb
      create  app/controllers/oauth_clients_controller.rb
      invoke  test_unit
      create    test/oauth_controller_test_helper.rb
      create    test/functional/oauth_controller_test.rb
      create    test/functional/oauth_clients_controller_test.rb
      create    test/unit/client_application_test.rb
      create    test/unit/oauth_token_test.rb
      create    test/unit/oauth_nonce_test.rb
      invoke  erb
No value provided for required arguments 'name'
Loaded suite script/rails
Started

Finished in 0.000163 seconds.

0 tests, 0 assertions, 0 failures, 0 errors

As you can see, it dies right after "invoke erb". On the other hand, if you use "rails g oauth_provider provider" it will generate the rest without a complaint.

(running on Rails 3.0.3, Ruby 1.8.6)

OAuth-plugin assumes OAuth credentials should be associated with User model

We would like to use the OAuth-plugin gem for a model other than User. Looking at the code, we are unsure what it would take to modify the codebase to support such a feature. We were hoping for some guidance on whether or not the architecture can even tolerate such an adaptation (for example, we noticed it depends on current_user).

Can you offer insight into:

  • Whether this configurability is a planned feature
  • How to go about taking a stab at adapting the code base

Thanks!

oauth2 consumer support for Rails3

Hi

Just wondering if adding oAuth2 consumer support is on the roadmap for the rails3 branch and if so when you think it might be available? I see it's there for providers, but looks like it's not for consumers.

Thanks

Specified key was too long; max key length is 767 bytes

consumer_tokens table
t.string :token, :limit => 1024 # This has to be huge because of Yahoo's excessively large tokens
change to :
t.string :token, :limit => 128
:(
ERROR 1071 (42000): Specified Key was too Long; Max Key Length is 767 Bytes.

no such file to load -- activesupport

Using rails3 branch, after installing plugin and running the generator:

rake db:migrate
rake aborted!
no such file to load -- activesupport

(See full trace by running task with --trace)

authlogic

Hi,
have you tested your plugin with authlogic? Will it works?

Invalid OAuth request

Hello and sorry for my English.
I am using oauth 0.4.4 and oauth-plugin 0.4.0.pre4 gems.
When i trying to access my app as an OAuth Provider
8 consumer = OAuth::Consumer.new consumer_key, consumer_secret,
9 :site => 'http://localhost:3000/', :scheme => :body
10
11 request_token = consumer.get_request_token
consumer raises an exception
/home/lain/.rvm/gems/ruby-1.9.2-p136/gems/oauth-0.4.4/lib/oauth/consumer.rb:217:in token_request': 401 Unauthorized (OAuth::Unauthorized) from /home/lain/.rvm/gems/ruby-1.9.2-p136/gems/oauth-0.4.4/lib/oauth/consumer.rb:139:inget_request_token'
from private/test_app.rb:11:in `

'

Rails log for this request is

Started POST "/oauth/request_token" for 127.0.0.1 at 2011-02-22 21:17:54 +0300
  Processing by OauthController#request_token as */*
  Parameters: {"oauth_body_hash"=>"2jmj7l5rSw0yVb/vlWAYkK/YBwk=", "oauth_callback"=>"oob", "oauth_consumer_key"=>"GAdP34UY4zunPwhm9hePODITteHxplQ3oShNPuKs", "oauth_signature_method"=>"HMAC-SHA1", "oauth_timestamp"=>"1298398673", "oauth_nonce"=>"aDRQijPyYJYODaqdZvpD2RMrReixMVcWb0zYSpjI", "oauth_version"=>"1.0", "oauth_signature"=>"0kYXwbPnNZK7JLpVVtnLs+H5klQ="}
Rendered text template (0.0ms)
Completed 401 Unauthorized in 10ms (Views: 2.7ms | ActiveRecord: 0.0ms)

When I trying to simulate this request using curl, I'm going to get

$ curl 'http://127.0.0.1:3000/oauth/request_token' -d 'oauth_body_hash=2jmj7l5rSw0yVb%2fvlWAYkK%2fYBwk%3d&oauth_callback=oob&oauth_consumer_key=GAdP34UY4zunPwhm9hePODITteHxplQ3oShNPuKs&oauth_signature_method=HMAC-SHA1&oauth_timestamp=1298398673&oauth_nonce=aDRQijPyYJYODaqdZvpD2RMrReixMVcWb0zYSpjI&oauth_version=1.0&oauth_signature=0kYXwbPnNZK7JLpVVtnLs%2bH5klQ%3d' -v
* About to connect() to 127.0.0.1 port 3000 (#0)
*   Trying 127.0.0.1... connected
* Connected to 127.0.0.1 (127.0.0.1) port 3000 (#0)
> POST /oauth/request_token HTTP/1.1
> User-Agent: curl/7.19.7 (i486-pc-linux-gnu) libcurl/7.19.7 OpenSSL/0.9.8k zlib/1.2.3.3 libidn/1.15
> Host: 127.0.0.1:3000
> Accept: */*
> Content-Length: 309
> Content-Type: application/x-www-form-urlencoded
> 
< HTTP/1.1 401 Unauthorized 
< Access-Control-Allow-Origin: *
< Content-Type: text/html; charset=utf-8
< Cache-Control: no-cache
< X-Ua-Compatible: IE=Edge
< X-Runtime: 1.245471
< Server: WEBrick/1.3.1 (Ruby/1.9.2/2010-12-25)
< Date: Tue, 22 Feb 2011 23:57:49 GMT
< Content-Length: 21
< Connection: Keep-Alive
< 
* Connection #0 to host 127.0.0.1 left intact
* Closing connection #0
Invalid OAuth Request

My database contains one ClientApplication
ruby-1.9.2-p136 :001 > ClientApplication.all.to_a
=> [#<ClientApplication _id: 4d62f535e4279b2dec000001, created_at: 2011-02-21 23:28:53 UTC, updated_at: 2011-02-21 23:28:53 UTC, name: "...", url: "...", support_url: nil, callback_url: nil, key: "GAdP34UY4zunPwhm9hePODITteHxplQ3oShNPuKs", secret: "EQAD5fifIuC3qtAyrkIpqAEn39rK50Az55gxbVYD", user_id: nil>]

I had tried many versions of oauth and oauth-plugin but I never got any successful result.
Two test consumers I had googled for `oauth test' show me the same:
http://term.ie/oauth/example/client.php
http://dev.k42b3.com/index.php/oauth/consumer

I'm using devise 1.2.rc but I have disabled it by skip_before_filter :authenticate_user! in both Application and Oauth controllers.

oauth-plugin + Rails3 + devise.

I spent considerable time researching for this so I hope it helps someone:

After installing the plugin following Pelle's Readme I hit a wall with the following errors:

undefined method `callback_oauth_consumer_url' for #OauthConsumersController:0xb6652a28

Which I fixed by adding the following:

def callback
super
end

to oauth_consumers_controller.rb, which turned the error into:

undefined method `consumer_tokens' for #User:0xb659c7c8

It seemed like the User model was broken. Fixed it by using the gem files from the git repository. I did this by adding the following lines to my Gemfile:

gem 'devise', :git => "http://github.com/plataformatec/devise.git"
gem 'oauth', :git => "http://github.com/pelle/oauth.git"
gem 'oauth-plugin', :git => "http://github.com/alsemyonov/oauth-plugin.git", :branch => "rails3"

Implementation of application_controller_methods#oauth20_token correct?

I just stumbled upon these lines of code and wondered if they are correct.

In my case i invalidated an access_token (Oauth2) - but oauthenticate would still throw no 401 or alike - it just didn't set current_token (and therefore also didn't set a "current_client_application", which resulted in 500 errors in my views).

I scanned the implementation:

def oauth20_token
      return false unless defined?(Oauth2Token)
      token, options = token_and_options
      token ||= params[:oauth_token] || params[:access_token]
      if !token.blank?
        @oauth2_token = Oauth2Token.find_by_token(token)
        if @oauth2_token && @oauth2_token.authorized?
          controller.send :current_token=, @oauth2_token
        end
      end
      @oauth2_token!=nil
    end

shouldn't the last line read?

@current_token!=nil

Rails 2 can't find Railtie constant

Following the instructions for Rails 2.3.10 (although I am using Bundler in my rails 2 app):

# Gemfile
gem 'oauth', '~> 0.4.4'
gem "oauth-plugin", ">= 0.4.0.pre1"

$ bundle install
$ ./script/generate oauth_provider --test-unit --haml

Results in:

/Users/nesquena/.rvm/gems/ree-1.8.7-2010.02/gems/activesupport-2.3.10/lib/active_support/dependencies.rb:466:in `load_missing_constant': uninitialized constant Rails::Railtie (NameError)
    from /Users/nesquena/.rvm/gems/ree-1.8.7-2010.02/gems/activesupport-2.3.10/lib/active_support/dependencies.rb:106:in `const_missing'
    from /Users/nesquena/.rvm/gems/ree-1.8.7-2010.02/gems/oauth-plugin-0.4.0.pre4/lib/oauth-plugin.rb:16
    from /Users/nesquena/.rvm/gems/ree-1.8.7-2010.02/gems/bundler-1.0.10/lib/bundler/runtime.rb:68:in `require'
    from /Users/nesquena/.rvm/gems/ree-1.8.7-2010.02/gems/bundler-1.0.10/lib/bundler/runtime.rb:68:in `require'
    from /Users/nesquena/.rvm/gems/ree-1.8.7-2010.02/gems/bundler-1.0.10/lib/bundler/runtime.rb:66:in `each'
    from /Users/nesquena/.rvm/gems/ree-1.8.7-2010.02/gems/bundler-1.0.10/lib/bundler/runtime.rb:66:in `require'
    from /Users/nesquena/.rvm/gems/ree-1.8.7-2010.02/gems/bundler-1.0.10/lib/bundler/runtime.rb:55:in `each'
    from /Users/nesquena/.rvm/gems/ree-1.8.7-2010.02/gems/bundler-1.0.10/lib/bundler/runtime.rb:55:in `require'
    from /Users/nesquena/.rvm/gems/ree-1.8.7-2010.02/gems/bundler-1.0.10/lib/bundler.rb:120:in `require'
    from /Users/nesquena/Documents/Development/Miso/miso-server/config/environment.rb:14
    from /Users/nesquena/.rvm/gems/ree-1.8.7-2010.02/gems/rails-2.3.10/lib/initializer.rb:111:in `run'
    from /Users/nesquena/Documents/Development/Miso/miso-server/config/environment.rb:10
    from /Users/nesquena/.rvm/gems/ree-1.8.7-2010.02/gems/rails-2.3.10/lib/commands/generate.rb:1:in `require'
    from /Users/nesquena/.rvm/gems/ree-1.8.7-2010.02/gems/rails-2.3.10/lib/commands/generate.rb:1
    from ./script/generate:3:in `require'
    from ./script/generate:3

Looks like the Railtie is defined even in Rails 2 where the definition doesn't make sense.

Index key length in migration

There is a problem running the migration, due to key length which is too long if the table use utf-8:

== CreateOauthConsumerTokens: migrating ======================================
-- create_table(:consumer_tokens)
-> 0.0780s
-- add_index(:consumer_tokens, :token, {:unique=>true})
rake aborted!
Mysql::Error: Specified key was too long; max key length is 767 bytes: CREATE UNIQUE INDEX index_consumer_tokens_on_token ON consumer_tokens (token)

I don't know how to fix this in a ruby-way, but this sql does the trick:
execute("CREATE UNIQUE INDEX index_consumer_tokens_on_token ON consumer_tokens (token (100))")

It uses only the 100 first chacracters instead of the whole field.

RequestToken.exchange! seems to be broken in latest version 0.3.14

this line: return false unless oauth10? || verifier==provided_oauth_verifier

expects "oauth10?" to return false i guess. forcing me to declare OAUTH_10_SUPPORT in my environment.rb and set it to false before any access_token requests can be handed out. I couldn't find this anywhere in the documentation. I'm using authlogic but why should that matter? Anyway i'm just a beginner but after a day of debugging i came to the conclusion that maybe this is a bug?

Shouldn't rails generate oauth_provider also generate views?

Trying to use oauth-plugin with Rails 3 application. When running rails generate oauth_provider I get models and controllers generated successfully. But no views. Those are missing completely, though I think they should be generated as well. At least according to this tutorial: http://stakeventures.com/articles/2007/11/26/how-to-turn-your-rails-site-into-an-oauth-provider

Gemfile:

gem 'rails'
gem 'simple_form'
gem 'paperclip', '~> 2.3'
gem 'devise', '1.2.rc'
gem 'oa-oauth', :require => 'omniauth/oauth'
gem 'jquery-rails', '>= 0.2.6'
gem 'oauth'
gem 'oauth-plugin', '>=0.4.0.pre1'

These are generated:
invoke active_record
identical app/models/client_application.rb
identical app/models/oauth_token.rb
identical app/models/request_token.rb
identical app/models/access_token.rb
identical app/models/oauth2_token.rb
identical app/models/oauth2_verifier.rb
identical app/models/oauth_nonce.rb

Wonder is it an issue?

Updated twitter_token.rb for latest twitter gem

Hi

Your recent commit to incorporate the latest Twitter gem was still not working for me. I've modified twitter.rb controller with the following:

require 'twitter'
class TwitterToken < ConsumerToken
  TWITTER_SETTINGS={:site=>"http://api.twitter.com", :request_endpoint => 'http://api.twitter.com',}
  def self.consumer
    @consumer||=OAuth::Consumer.new credentials[:key],credentials[:secret],TWITTER_SETTINGS
  end

  def client
    Twitter.configure do |config|
      config.consumer_key = TwitterToken.consumer.key
      config.consumer_secret = TwitterToken.consumer.secret
      config.oauth_token = token
      config.oauth_token_secret = secret
    end
    @client ||= Twitter::Client.new
  end
end

I hope this helps someone, I was stuck for hours..

Desktop Applications

Hey,

great work on the gem!
One question though: Will it also work with Desktop Applications (which don't have a callback_url but normally exchange the request token for the access token, once the user closes the browser window (where he/she authorized the desktop app))?

Validation failed - Client application can't be blank

I'm new to rails and ruby in general, but I may be running into an issue with the oauth-plugin itself. I'm attempting to use the consumer portion of the logic to authorize my web app via a user's Twitter account. Everything is setup to the point that I'm redirected to Twitter for the authorization, but when the user is redirected back to my app, I receive an error when the token is being saved into the MongoDB database:

Mongoid::Errors::Validations in Oauth consumersController#callback

Validation failed - Client application can't be blank.

It seems the Token model is expecting a "Client application" property to be populated, but I can't find this property anywhere.

One thing to note is I'm using the latest branch which includes fixes by 3en for mongoid, but the only way I can get the models to work is by using 'referenced_in' instead of 'embedded_in'.

What am I doing wrong here? Thanks in advance. -Rob

Application trace:

app/models/consumer_token.rb:25:in find_or_create_from_access_token'
app/controllers/oauth_consumers_controller.rb:16:in callback'

Partial full trace:

vendor/ruby/1.8/gems/mongoid-2.0.0.rc.7/lib/mongoid/persistence.rb:234:in fail_validate!'
vendor/ruby/1.8/gems/mongoid-2.0.0.rc.7/lib/mongoid/persistence.rb:75:in save!' vendor/ruby/1.8/gems/mongoid-2.0.0.rc.7/lib/mongoid/relations/referenced/many.rb:90:in create!'
vendor/ruby/1.8/gems/simple_oauth-0.1.4/lib/simple_oauth/core_ext/object.rb:6:in tap' vendor/ruby/1.8/gems/mongoid-2.0.0.rc.7/lib/mongoid/relations/referenced/many.rb:89:in create!'
app/models/consumer_token.rb:25:in find_or_create_from_access_token' vendor/ruby/1.8/bundler/gems/oauth-plugin-f805e8c359b1/lib/oauth/models/consumers/token.rb:38:in find_or_create_from_request_token'
vendor/ruby/1.8/bundler/gems/oauth-plugin-f805e8c359b1/lib/oauth/controllers/consumer_controller.rb:35:in callback' app/controllers/oauth_consumers_controller.rb:16:in callback'`

Edit: More info - after stepping into the framework code, I can see that the Token class is expecting a client_application_id to have a value. I didn't think a consumer token needed to be associated with a client application?

oAuth2 Support for Rails 2.3.5?

Hi there,

i'm currently evaluating the use of an oauth gem to have oAuth Provider functionality. I saw that oAuth 2 ist supported in your gem, but only in the branch "rails3". Is the code in this branch somewhat compat to rails 2 or is support for oAuth 2 planned in the master branch?

Thanks for your help

Could not find "oauth2_webserver_authorize.html.erb" in any of your source paths.

Hey,
i've started a Rails3 application and i'm hoping to turn it into an OAuth provider application.

I have the following specified in my Gemfile:

gem 'oauth'
gem 'oauth-plugin', :git => 'git://github.com/pelle/oauth-plugin.git', :branch => 'rails3'

and i ran 'bundle install' and got the following gems installed:

Using oauth (0.4.1)
Using oauth-plugin (0.3.14) from git://github.com/pelle/oauth-plugin.git (at rails3)

I then ran the generator command 'rails g oauth_provider' and got a bunch of generated files:

  create  app/models/client_application.rb
  create  app/models/oauth_token.rb
  create  app/models/request_token.rb
  create  app/models/access_token.rb
  create  app/models/oauth2_token.rb
  create  app/models/oauth2_verifier.rb
  create  app/models/oauth_nonce.rb
  create  app/controllers/oauth_controller.rb
  create  app/controllers/oauth_clients_controller.rb
   route  match '/oauth',               :to => 'oauth#index',         :as => :oauth
   route  match '/oauth/authorize',     :to => 'oauth#authorize',     :as => :authorize
   route  match '/oauth/request_token', :to => 'oauth#request_token', :as => :request_token
   route  match '/oauth/access_token',  :to => 'oauth#access_token',  :as => :access_token
   route  match '/oauth/token',         :to => 'oauth#token',         :as => :token
   route  match '/oauth/test_request',  :to => 'oauth#test_request',  :as => :test_request
   route  resources :oauth_clients
  create  spec/models/client_application_spec.rb
  create  spec/models/oauth_token_spec.rb
  create  spec/models/oauth2_token_spec.rb
  create  spec/models/oauth2_verifier_spec.rb
  create  spec/models/oauth_nonce_spec.rb
  create  spec/fixtures/client_applications.yml
  create  spec/fixtures/oauth_tokens.yml
  create  spec/fixtures/oauth_nonces.yml
  create  spec/controllers/oauth_controller_spec_helper.rb
  create  spec/controllers/oauth_controller_spec.rb
  create  spec/controllers/oauth_clients_controller_spec.rb
  create  app/views/oauth_clients/_form.html.erb
  create  app/views/oauth_clients/new.html.erb
  create  app/views/oauth_clients/index.html.erb
  create  app/views/oauth_clients/show.html.erb
  create  app/views/oauth_clients/edit.html.erb
  create  app/views/oauth/authorize.html.erb

and at the end i got 'Could not find "oauth2_webserver_authorize.html.erb" in any of your source paths.'

any ideas?

OAuth Invalid Request on POST and not GET. Why?

We're getting weird issues with our consumers where GET requests protected by oauth work great, but POST are always getting OAuth Invalid Requests. I've tried having them switch from query_string to auth headers, and vice versa but still not working.

Any ideas about this?

two-legged?

Has anyone modified this to support two-legged oauth?
Any tips/advice/code?

undefined method `consumer_tokens'

I've been having a few issues with getting the consumer working properly. I first had to run the generator with any extra parameter to get it to generate the views, I then had to add the references routes manually:

resources :oauth_consumers do
    get :callback, :on => :member
end

As well as the callback method to the controller:

def callback
    super
end

I've created my own token class to support Dopplr (pretty much a copy of the TwitterToken class)

require 'dopplr'
class DopplrToken < ConsumerToken
  TRIPIT_SETTINGS={
    :site=>"https://www.dopplr.com",
  }

  def self.consumer
    @consumer||=OAuth::Consumer.new credentials[:key],credentials[:secret],TRIPIT_SETTINGS
  end

  def self.client
    unless @client
      @dopplr_oauth=Dopplr::OAuth.new DopplrToken.consumer.key,DopplrToken.consumer.secret
      dopplr_oauth.authorize_from_access token,secret
      @client=Dopplr::Base.new(@dopplr_oauth)
    end

    @client
  end
end

I've added the line to the user model:

has_one :dopplr, :class_name=>"DopplrToken", :dependent=>:destroy

But now I get this error when I'm redirected to the callback URL:

Undefined method `consumer_tokens' for #<User:0x103335848>

Adding has_many :consumer_tokens to the user model made the callback work, but now there's 'Consumer' listed on the index page, rather than identifying it as Dopplr. Is there something wrong with the callback method that doesn't identify the service class properly?

ouath2_authorize.html.erb issues and won't redirect back to client app's url...

hi.

I have to comment out oauth2_authorize.html.erb in order for it to "work" (i.e., show up)

<%# link_to @token.client_application.name,@token.client_application.url %> (<%# link_to @token.client_application.url,@token.client_application.url %>

So @token is being passed as Nil::NIlClass and that doesn't have an associaiton. So the only way to get passed this was for me to comment them out.

Now, i think the same @token being nil is effecting the second part.

In the oauth2_authorize.html.erb file, I can "authorize" the app , but after clicking submit it doesn't redirect me back to my original app.com/auth/whatever/callback like it should.

Using omniauth's provider :oauth2 I think I'm setting it up right, but they don't have a spec to copy from in their tests... so maybe they send the url different. See, I tried oauth as the provider and I'd get back to my callback url, but there were other issues that screwed that up.

I'll take any help. thanks.

Rails 2.0.2 generate oauth_consumer gives errors

On Rails 2.0.2 & Ruby 1.8.7

running script/generate oauth_consumer give the error

/vendor/plugins/oauth-plugin/lib/oauth-plugin.rb:6: undefined method `version' for Rails:Module (NoMethodError)

Removing the rails 3 version check, running the script again then gives

/vendor/rails/activerecord/lib/../../activesupport/lib/active_support/dependencies.rb:263:in load_missing_constant': uninitialized constant Rails::Railtie (NameError) vendor/rails/activerecord/lib/../../activesupport/lib/active_support/dependencies.rb:453:inconst_missing'
from /u/apps/netadventist3/current/vendor/plugins/oauth-plugin/lib/oauth-plugin.rb:16

Unfortunately the app I'm extending has Rails 2.0.2 frozen in

Proper bundler support.

Hello,

When you add to the Gemfile:
gem 'oauth-plugin', '~> 0.4.1.pre1'

It requires the lib/oauth-plugin.rb by default (which is empty). And there's no way to require rails/init, because it is outside of the lib directory.

Could you move the rails/init.rb file to the lib directory? So at least I could write something like:
gem 'oauth-plugin', '~> 0.4.1.pre1', :require => 'oauth/rails'

Thank you,

Ruby 1.9.2, Rails 3.0.7: Cannot install oauth-plugin

Hello, I'm trying to install the auth-plugin by following the instructions, but I get the following error after adding

gem "oauth-plugin", ">=0.4.0.pre1" to Gemfile and running bundle install

cp: /home/users/dimitar/.bundler/tmp/1074/gems/oauth-plugin-0.4.0.pre4 and /home/users/dimitar/.bundler/tmp/1074/gems/oauth-plugin-0.4.0.pre4 are identical (not copied).
cp: /home/users/dimitar/.bundler/tmp/1074/specifications/oauth-plugin-0.4.0.pre4.gemspec and /home/users/dimitar/.bundler/tmp/1074/specifications/oauth-plugin-0.4.0.pre4.gemspec are identical (not copied).

bundle show gives out:

Gems included by the bundle:
Could not find oauth-plugin-0.4.0.pre4 in any of the sources

If I go with just gem "oauth-plugin" in the Gemfile, the gem installs okay, but then I am unable to generate OAuth and OAuth controllers:

$ rails generate oauth_consumer
Could not find generator oauth_consumer.

Any suggestions?

Mongoid Issue with @provider.find_by_key etc

The issue is same
https://github.com/pelle/oauth-plugin/issues/closed/#issue/27

lib/oauth/controllers/application_controller_methods.rb
80 @oauth2_token = Oauth2Token.find_by_token(token)
139 @client_application = ClientApplication.find_by_key(request_proxy.consumer_key)

lib/oauth/controllers/provider_controller.rb
35 @client_application = ClientApplication.find_by_key params[:client_id]
53 @token = ::RequestToken.find_by_token params[:oauth_token]
61 @token = current_user.tokens.find_by_token params[:token]
122 @client_application = ClientApplication.find_by_key params[:client_id]
152 @client_application = ClientApplication.find_by_key params[:client_id]
182 @verification_code = @client_application.oauth2_verifiers.find_by_token params[:code]

Mongoid does not recognise this.
undefined method find_by_xxx....

Solution is to override or change this line to
find(:first,:conditions=>{:xxx=>....})
or
where(:xxx=>...).first

Callback Issue

Hi,

I've added:

def callback
super
end

Into my controller file and can now connect to twitter. However, it sends the request back to:

NoMethodError in OauthConsumersController#callback

undefined method `consumer_tokens' for #User:0x0000010276ba80

I'm really not sure what's happening?

Thanks

Simon

oauth_token_test fails (missing provided_oauth_verifier)

Hi,

I ran the unit tests after doing a script/generate oauth_provider --test-unit, 2 small issues in the file test/unit/oauth_token_test.rb generated:

1 - there are 2 tests named "test_should_not_exchange_without_approval", I renamed the second one to "test_should_exchange_with_approval"
2 - line 48 of the file, a provided_oauth_verifier should be set after the @token.authorize!
Here is what i did to pass the test:

@token.authorize!(users(:user_2))
@token.provided_oauth_verifier = @token.verifier
@access = @token.exchange!

I thought this might help for other users :) And many thanks for the nice work on this gem

Cheers,

Maxime

PS: i'm under Ruby 1.9.1 with the gems oauth (0.4.0) and oauth-plugin (0.3.14)

The action 'callback' could not be found for OauthConsumersController

Hi~
I want to connect with an oauth provider. I follow the instruction step by step, however on the redirected path (/oauth_consumers/sina/callback) I get an "Unknown action" error (The action 'callback' could not be found for OauthConsumersController).

What should I do?
Thanks a lot!

This plugin requires the portablecontacts gem

Why does this require the portablecontacts gem? Shouldn't it be the other way around? In any case, I didn't want to include the portablecontacts gem in my application, but I'm forced to unless I fork this project.

Trusted sites

Hi,
Is there any ability to mark site as trusted? For example - somebody have some sites - auth.site.com (as oauth provider) and s1.site.com, s2.site.com etc as consumers. Of course - owner would like to skip step "Do you agree to add site s1.site.com as trusted?", but for security reason would like to not mark other sites like othersite.com, othersite2.com as trusted. I'm planning to add this functionality to plugin, but i'd like to discuss how to develop with you, because i'm a newbie in oauth. Any ideas? From my understanding - there are need to add password for Request Token and if password is not present - use default callflow. Maybe you have another vision of this?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.