Skip to content

Commit

Permalink
Add AngelList OAuth2 Strategy
Browse files Browse the repository at this point in the history
  • Loading branch information
joshuaxls committed Aug 24, 2011
1 parent 51f7611 commit 047984b
Show file tree
Hide file tree
Showing 4 changed files with 64 additions and 0 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ OmniAuth currently supports the following external providers:

* via OAuth (OAuth 1.0, OAuth 2, and xAuth)
* 37signals ID (credit: [mbleigh](https://github.com/mbleigh))
* AngelList (credit: [joshuaxls](https://github.com/joshuaxls))
* Bit.ly (credit: [philnash](https://github.com/philnash))
* Blogger (credit: [dsueiro-backing](https://github.com/dsueiro-backing))
* Cobot (credit: [kamal](https://github.com/kamal))
Expand Down
1 change: 1 addition & 0 deletions oa-oauth/lib/omniauth/oauth.rb
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ module Strategies
autoload :YouTube, 'omniauth/strategies/oauth/you_tube'

autoload :OAuth2, 'omniauth/strategies/oauth2'
autoload :AngelList, 'omniauth/strategies/oauth2/angellist'
autoload :Bitly, 'omniauth/strategies/oauth2/bitly'
autoload :Cobot, 'omniauth/strategies/oauth2/cobot'
autoload :Dailymile, 'omniauth/strategies/oauth2/dailymile'
Expand Down
57 changes: 57 additions & 0 deletions oa-oauth/lib/omniauth/strategies/oauth2/angellist.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
require 'omniauth/oauth'
require 'multi_json'

module OmniAuth
module Strategies
# Authenticate to AngelList utilizing OAuth 2.0 and retrieve
# basic user information.
#
# @example Basic Usage
# use OmniAuth::Strategies::AngelList, 'API Key', 'Secret Key'
class AngelList < OmniAuth::Strategies::OAuth2
# @param [Rack Application] app standard middleware application parameter
# @param [String] client_id the application id as [registered on AngelList](http://angel.co/api/oauth/faq)
# @param [String] client_secret the application secret as [registered on AngelList](http://bit.ly/api/oauth/faq )
def initialize(app, client_id=nil, client_secret=nil, options={}, &block)
client_options = {
:site => 'https://api.angel.co/',
:authorize_url => 'https://angel.co/api/oauth/authorize',
:token_url => 'https://angel.co/api/oauth/token'
}

super(app, :angellist, client_id, client_secret, client_options, options, &block)
end

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

def user_info
{
'name' => user_data['name'],
'bio' => user_data['bio'],
'image' => user_data['image'],
'urls' => {
'AngelList' => user_data['angellist_url'],
'Website' => user_data['online_bio_url']
},
}
end

def user_data
@data ||= begin
@access_token.options[:mode] = :query
@access_token.get('/1/me').parsed
end
end
end
end
end
5 changes: 5 additions & 0 deletions oa-oauth/spec/omniauth/strategies/oauth2/angellist_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
require 'spec_helper'

describe OmniAuth::Strategies::AngelList do
it_should_behave_like "an oauth2 strategy"
end

0 comments on commit 047984b

Please sign in to comment.