Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/softprops/omniauth
Browse files Browse the repository at this point in the history
  • Loading branch information
Michael Bleigh committed Dec 29, 2010
2 parents 6b79dd7 + 15666c8 commit d6dd129
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 6 deletions.
45 changes: 39 additions & 6 deletions oa-oauth/lib/omniauth/strategies/meetup.rb
Expand Up @@ -3,20 +3,53 @@

module OmniAuth
module Strategies
#
# Authenticate to Meetup via OAuth and retrieve an access token for API usage
#
# Authenticate with Meetup via OAuth and retrieve an access token for API usage
#
# Usage:
#
# use OmniAuth::Strategies::Meetup, 'consumerkey', 'consumersecret'
#
class Meetup < OmniAuth::Strategies::OAuth
# Initialize meetup middleware
# @param [Rack Application] app standard middleware application parameter
# @param [String] consumer_key the application consumer id
# @param [String] consumer_secret the application consumer secret
# @option options [Boolean, true] :sign_in When true, use a sign-in flow instead of the authorization flow.
def initialize(app, consumer_key = nil, consumer_secret = nil, options = {}, &block)
auth_path = (options[:sign_in] == false) ? 'http://www.meetup.com/authorize' : 'http://www.meetup.com/authenticate'

super(app, :meetup, consumer_key, consumer_secret,
# :site => 'https://api.meetup.com',
{:request_token_path => "https://api.meetup.com/oauth/request",
:access_token_path => "https://api.meetup.com/oauth/access",
:authorize_path => "http://www.meetup.com/authorize/"}, options)
{ :request_token_path => "https://api.meetup.com/oauth/request",
:access_token_path => "https://api.meetup.com/oauth/access",
:authorize_path => auth_path }, options)
end

def auth_hash
OmniAuth::Utils.deep_merge(super, {
'uid' => member['id'],
'user_info' => user_info,
'extra' => { 'user_hash' => member }
})
end

def user_info
{
'name' => member['name'],
'image' => member['photo_url'],
'location' => member['city'],
'urls' => {
'profile' => member['link']
}
}
end

def member
@member ||= parse(@access_token.get('https://api.meetup.com/members.json?relation=self').body)['results'][0]
end

def parse(response)
MultiJson.decode(response)
end
end
end
Expand Down
9 changes: 9 additions & 0 deletions oa-oauth/spec/omniauth/strategies/meetup_spec.rb
Expand Up @@ -2,4 +2,13 @@

describe OmniAuth::Strategies::Meetup do
it_should_behave_like 'an oauth strategy'
it 'should use the authenticate (sign in) path by default' do
s = strategy_class.new(app, 'abc', 'def')
s.consumer.options[:authorize_path].should == 'http://www.meetup.com/authenticate'
end

it 'should use the authorize path if :sign_in is false' do
s = strategy_class.new(app, 'abc', 'def', :sign_in => false)
s.consumer.options[:authorize_path].should == 'http://www.meetup.com/authorize'
end
end

0 comments on commit d6dd129

Please sign in to comment.