Permalink
Browse files

first commit

  • Loading branch information...
0 parents commit e28012a17c0aa39bed880c331709ba2099b2a23a @fmhun committed Dec 5, 2011
No changes.
@@ -0,0 +1,7 @@
+source 'http://rubygems.org'
+
+gemspec
+
+group :example do
+ gem 'sinatra'
+end
@@ -0,0 +1,7 @@
+Copyright (c) 2011 Florian Mhun
+
+Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,13 @@
+#Mailchimp Strategie
+
+MailChimp OAuth2 strategy for OmniAuth 1.0
+
+#License
+
+Copyright (c) 2011 Florian Mhun
+
+Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,7 @@
+require 'bundler'
+Bundler::GemHelper.install_tasks
+
+require 'rspec/core/rake_task'
+RSpec::Core::RakeTask.new(:spec)
+
+task :default => :spec
@@ -0,0 +1,35 @@
+require 'rubygems'
+require 'bundler'
+require 'sinatra'
+require 'omniauth'
+require 'omniauth-mailchimp'
+
+OpenSSL::SSL::VERIFY_PEER = OpenSSL::SSL::VERIFY_NONE
+
+class App < Sinatra::Base
+ get '/' do
+ <<-HTML
+ <ul>
+ <li><a href='/auth/mailchimp'>Sign in with Mailchimp</a></li>
+ </ul>
+ HTML
+ end
+
+ get '/auth/:provider/callback' do
+ content_type 'text/plain'
+ request.env['omniauth.auth'].to_hash.inspect rescue "No Data"
+ end
+
+ get '/auth/failure' do
+ content_type 'text/plain'
+ request.env['omniauth.auth'].to_hash.inspect rescue "No Data"
+ end
+end
+
+use Rack::Session::Cookie, :secret => ENV['RACK_COOKIE_SECRET']
+
+use OmniAuth::Builder do
+ provider :mailchimp, "924877707893", "b8c494ebef4e4bb3879daa69e8302896", {}
+end
+
+run App.new
@@ -0,0 +1 @@
+require "omniauth/mailchimp"
@@ -0,0 +1 @@
+require 'omniauth/strategies/mailchimp'
@@ -0,0 +1,5 @@
+module OmniAuth
+ module GoogleOauth2
+ VERSION = "0.1.0"
+ end
+end
@@ -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
@@ -0,0 +1,24 @@
+# -*- encoding: utf-8 -*-
+require File.expand_path('../lib/omniauth/mailchimp/version', __FILE__)
+
+Gem::Specification.new do |gem|
+ gem.add_dependency 'omniauth', '~> 1.0'
+
+ gem.authors = ["Florian Mhun"]
+ gem.email = ["florian.mhun@gmail.com"]
+ gem.description = %q{MailChimp OAuth2 strategy for OmniAuth 1.0}
+ gem.summary = %q{MailChimp OAuth2 strategy for OmniAuth 1.0}
+ gem.homepage = "floomoon.org/project/omniauth-mailchimp"
+
+ gem.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
+ gem.files = `git ls-files`.split("\n")
+ gem.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
+ gem.name = "omniauth-mailchimp"
+ gem.require_paths = ["lib"]
+ gem.version = OmniAuth::Mailchimp::VERSION
+
+ gem.add_runtime_dependency 'omniauth-oauth2'
+
+ gem.add_development_dependency 'rspec', '~> 2.6.0'
+ gem.add_development_dependency 'rake'
+end

0 comments on commit e28012a

Please sign in to comment.