Skip to content
Browse files

Merge remote-tracking branch 'brandonweiss/rdio_strategy'

  • Loading branch information...
2 parents 6944a2c + 1df7cf8 commit b3bcdda9ab7de5d7d8e8b8b24327520ac524e616 @sferik sferik committed Apr 24, 2011
View
9 README.markdown
@@ -10,7 +10,7 @@ OmniAuth is a new Rack-based authentication system for multi-provider external a
To install OmniAuth, simply install the gem:
gem install omniauth
-
+
## Providers
OmniAuth currently supports the following external providers:
@@ -36,6 +36,7 @@ OmniAuth currently supports the following external providers:
* Miso (credit: [rickenharp](https://github.com/rickenharp))
* Mixi (credit: [kiyoshi](https://github.com/kiyoshi))
* Netflix (credit: [caged](https://github.com/caged))
+ * Rdio (via [brandonweiss](http://github.com/brandonweiss))
* Salesforce (via [CloudSpokes](http://www.cloudspokes.com))
* SmugMug (credit: [pchilton](https://github.com/pchilton))
* SoundCloud (credit: [leemartin](https://github.com/leemartin))
@@ -70,13 +71,13 @@ OmniAuth is a collection of Rack middleware. To use a single strategy, you simpl
require 'oa-oauth'
use OmniAuth::Strategies::Twitter, 'CONSUMER_KEY', 'CONSUMER_SECRET'
-
+
Now to initiate authentication you merely need to redirect the user to `/auth/twitter` via a link or other means. Once the user has authenticated to Twitter, they will be redirected to `/auth/twitter/callback`. You should build an endpoint that handles this URL, at which point you will will have access to the authentication information through the `omniauth.auth` parameter of the Rack environment. For example, in Sinatra you would do something like this:
get '/auth/twitter/callback' do
auth_hash = request.env['omniauth.auth']
end
-
+
The hash in question will look something like this:
{
@@ -88,7 +89,7 @@ The hash in question will look something like this:
# ...
}
}
-
+
The `user_info` hash will automatically be populated with as much information about the user as OmniAuth was able to pull from the given API or authentication provider.
## Resources
View
1 oa-oauth/lib/omniauth/oauth.rb
@@ -40,5 +40,6 @@ module Strategies
autoload :Teambox, 'omniauth/strategies/teambox'
autoload :Tumblr, 'omniauth/strategies/tumblr'
autoload :Vkontakte, 'omniauth/strategies/vkontakte'
+ autoload :Rdio, 'omniauth/strategies/rdio'
end
end
View
45 oa-oauth/lib/omniauth/strategies/rdio.rb
@@ -0,0 +1,45 @@
+require 'omniauth/oauth'
+require 'multi_json'
+
+module OmniAuth
+ module Strategies
+ #
+ # Authenticate to Rdio via OAuth and retrieve basic user information.
+ # Usage:
+ # use OmniAuth::Strategies::Rdio, 'consumerkey', 'consumersecret'
+ #
+ class Rdio < OmniAuth::Strategies::OAuth
+ def initialize(app, consumer_key = nil, consumer_secret = nil, options = {}, &block)
+ opts = {
+ :site => 'http://api.rdio.com',
+ :request_token_path => "/oauth/request_token",
+ :access_token_path => "/oauth/access_token",
+ :authorize_url => "https://www.rdio.com/oauth/authorize"
+ }
+ super(app, :rdio, consumer_key, consumer_secret, opts, options, &block)
+ end
+
+ def auth_hash
+ OmniAuth::Utils.deep_merge(super, {
+ 'uid' => user_hash['key'],
+ 'user_info' => user_info,
+ 'extra' => { 'user_hash' => user_hash }
+ })
+ end
+
+ def user_info
+ user = user_hash
+ {
+ 'nickname' => user['username'],
+ 'first_name' => user['firstName'],
+ 'last_name' => user['lastName'],
+ 'name' => "#{user['firstName']} #{user['lastName']}"
+ }
+ end
+
+ def user_hash
+ @user_hash ||= MultiJson.decode(@access_token.post("http://api.rdio.com/1/", { :method => 'currentUser', :extras => 'username' }).body)['result']
+ end
+ end
+ end
+end
View
5 oa-oauth/spec/omniauth/strategies/rdio_spec.rb
@@ -0,0 +1,5 @@
+require File.expand_path('../../../spec_helper', __FILE__)
+
+describe OmniAuth::Strategies::Rdio do
+ it_should_behave_like "an oauth strategy"
+end

0 comments on commit b3bcdda

Please sign in to comment.
Something went wrong with that request. Please try again.