Skip to content
Browse files

Merge pull request #439 from srbiv/master

Added a OAuth2 strategy for Mailchimp
  • Loading branch information...
2 parents 72a93c5 + bf21d8b commit 2ef16139575ed66db5dcea46fa2dc69d98d307b1 @sferik sferik committed Aug 23, 2011
View
1 README.md
@@ -47,6 +47,7 @@ OmniAuth currently supports the following external providers:
* Instapaper (credit: [micpringle](https://github.com/micpringle))
* LastFM (credit: [tictoc](https://github.com/tictoc))
* LinkedIn (credit: [mbleigh](https://github.com/mbleigh))
+ * Mailchimp (via [srbiv](http://github.com/srbiv))
* Mailru (credit: [lexer](https://github.com/lexer))
* Meetup (credit [coderoshi](https://github.com/coderoshi))
* Miso (credit: [rickenharp](https://github.com/rickenharp))
View
3 oa-oauth/lib/omniauth/oauth.rb
@@ -51,7 +51,8 @@ module Strategies
autoload :GoogleOAuth2, 'omniauth/strategies/google_oauth2'
autoload :Gowalla, 'omniauth/strategies/oauth2/gowalla'
autoload :Instagram, 'omniauth/strategies/oauth2/instagram'
- autoload :Liveid, 'omniauth/strategies/oauth2/liveid'
+ autoload :Liveid, 'omniauth/strategies/oauth2/liveid'
+ autoload :Mailchimp, 'omniauth/strategies/oauth2/mailchimp'
autoload :Mailru, 'omniauth/strategies/oauth2/mailru'
autoload :Mixi, 'omniauth/strategies/oauth2/mixi'
autoload :Renren, 'omniauth/strategies/oauth2/renren'
View
39 oa-oauth/lib/omniauth/strategies/oauth2/mailchimp.rb
@@ -0,0 +1,39 @@
+require 'omniauth/oauth'
+require 'multi_json'
+
+module OmniAuth
+ module Strategies
+ class Mailchimp < OmniAuth::Strategies::OAuth2
+
+ def initialize(app, client_id=nil, client_secret=nil, options={}, &block)
+ client_options = {
+ :authorize_url => 'https://login.mailchimp.com/oauth2/authorize',
+ :token_url => 'https://login.mailchimp.com/oauth2/token',
+ }
+ super(app, :mailchimp, client_id, client_secret, client_options, options, &block)
+ end
+
+ def auth_hash
+ data = user_data
+ OmniAuth::Utils.deep_merge(
+ super, {
+ 'uid' => @access_token.client.id,
+ 'extra'=> {
+ 'user_hash' => data
+ }
+ }
+ )
+ end
+
+ def user_data
+ @data ||= MultiJson.decode(@access_token.get("https://login.mailchimp.com/oauth2/metadata").body)
+ rescue ::OAuth2::Error => e
+ if e.response.status == 302
+ @data ||= MultiJson.decode(@access_token.get(e.response.headers['location']))
+ else
+ raise e
+ end
+ end
+ end
+ end
+end
View
6 oa-oauth/spec/omniauth/strategies/oauth2/mailchimp_spec.rb
@@ -0,0 +1,6 @@
+# oa-oauth/spec/omniauth/strategies/rdio_spec.rb
+require File.expand_path('../../../spec_helper', __FILE__)
+
+describe OmniAuth::Strategies::Mailchimp do
+ it_should_behave_like "an oauth strategy"
+end

0 comments on commit 2ef1613

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