Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Added a OAuth2 strategy for Mailchimp #439

Merged
merged 2 commits into from

4 participants

@srbiv

Added a OAuth2 strategy for Mailchimp's OAuth provider. http://apidocs.mailchimp.com/oauth2/

@lorennorman

alphabetical order fail

Stafford Brooke ordering fix bf21d8b
@skalnik

Nicely done! Really awesome work. The only thing that could make it better may be a more in-depth test.

@sferik sferik merged commit 2ef1613 into from
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Aug 23, 2011
  1. [#17145261] Added Mailchimp OAuth2 Strategy

    Stafford Brooke authored
  2. ordering fix

    Stafford Brooke authored
This page is out of date. Refresh to see the latest.
View
1  README.md
@@ -51,6 +51,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
Something went wrong with that request. Please try again.