README.rdoc in oauth-plugin-0.4.0.pre5 vs README.rdoc in oauth-plugin-0.4.0.pre6
- old
+ new
@@ -26,11 +26,11 @@
== Installation (Rails 3.0)
Add the plugin to your Gemfile:
- gem "oauth-plugin", ">=0.4.0.pre1"
+ gem "oauth-plugin", ">= 0.4.0.pre1"
And install it:
bundle install
@@ -88,11 +88,11 @@
=== 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]
+ 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:
@@ -113,11 +113,11 @@
=== 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]
+ has_many :tokens, :class_name => "OauthToken", :order => "authorized_at desc", :include => [:client_application]
=== Migrate database
The database is defined in:
@@ -139,17 +139,17 @@
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
+ 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
+ remove_column :oauth_tokens, :callback_url
+ remove_column :oauth_tokens, :verifier
end
end
=== Change code
@@ -166,11 +166,11 @@
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
+ 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.
@@ -189,11 +189,11 @@
self.save
end
def exchange!
return false unless authorized?
- return false unless oauth10? || verifier==provided_oauth_verifier
+ return false unless oauth10? || verifier == provided_oauth_verifier
RequestToken.transaction do
access_token = AccessToken.create(:user => user, :client_application => client_application)
invalidate!
access_token
@@ -202,16 +202,16 @@
def to_query
if oauth10?
super
else
- "#{super}&oauth_callback_confirmed=true"
+ "#{super}&oauth_callback_confirmed = true"
end
end
def oob?
- self.callback_url=='oob'
+ self.callback_url == 'oob'
end
def oauth10?
(defined? OAUTH_10_SUPPORT) && OAUTH_10_SUPPORT && self.callback_url.blank?
end
@@ -284,12 +284,12 @@
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]
+ 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
@@ -328,37 +328,37 @@
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)
+ 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",
+ :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"
+ :hour_feed => {
+ :key => "",
+ :secret => "",
+ :options = {
+ :site => "http://hourfeed.com"
}
},
- :nu_bux=>{
- :key=>"",
- :secret=>"",
- :super_class=>"OpenTransactToken", # if a OAuth service follows a particular standard
+ :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"
+ :options => {
+ :site => "http://nubux.heroku.com"
}
}
}
You can add any of the options that the OAuth::Consumer.new accepts to the options hash: http://oauth.rubyforge.org/rdoc/classes/OAuth/Consumer.html
@@ -371,15 +371,15 @@
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
+ has_one :fire_eagle, :class_name => "FireEagleToken", :dependent => :destroy
And you could do:
- @location=@user.fire_eagle.client.location
+ @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 http://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:
@@ -411,14 +411,14 @@
=== 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)
+ 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: