omniauth-angellist 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/..gemspec +24 -0
- data/.gitignore +4 -0
- data/Gemfile +4 -0
- data/README.md +35 -0
- data/Rakefile +7 -0
- data/lib/..rb +5 -0
- data/lib/omniauth/strategies/angellist.rb +43 -0
- data/lib/omniauth-angellist/version.rb +5 -0
- data/lib/omniauth-angellist.rb +2 -0
- data/omniauth-angellist.gemspec +27 -0
- data/spec/omniauth/strategies/angellist_spec.rb +112 -0
- data/spec/spec_helper.rb +6 -0
- data/spec/support/shared_examples.rb +37 -0
- metadata +157 -0
data/..gemspec
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
$:.push File.expand_path("../lib", __FILE__)
|
3
|
+
require "./version"
|
4
|
+
|
5
|
+
Gem::Specification.new do |s|
|
6
|
+
s.name = "."
|
7
|
+
s.version = .::VERSION
|
8
|
+
s.authors = ["Sebastian Rabuini"]
|
9
|
+
s.email = ["srabuini@gmail.com"]
|
10
|
+
s.homepage = ""
|
11
|
+
s.summary = %q{TODO: Write a gem summary}
|
12
|
+
s.description = %q{TODO: Write a gem description}
|
13
|
+
|
14
|
+
s.rubyforge_project = "."
|
15
|
+
|
16
|
+
s.files = `git ls-files`.split("\n")
|
17
|
+
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
18
|
+
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
19
|
+
s.require_paths = ["lib"]
|
20
|
+
|
21
|
+
# specify any dependencies here; for example:
|
22
|
+
# s.add_development_dependency "rspec"
|
23
|
+
# s.add_runtime_dependency "rest-client"
|
24
|
+
end
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/README.md
ADDED
@@ -0,0 +1,35 @@
|
|
1
|
+
# OmniAuth AngelList
|
2
|
+
|
3
|
+
This gem contains the AngelList strategy for OmniAuth.
|
4
|
+
|
5
|
+
AngelList uses the OAuth2 flow, you can read about it here: http://angel.co/api/oauth/faq
|
6
|
+
|
7
|
+
## How To Use It
|
8
|
+
|
9
|
+
So let's say you're using Rails, you need to add the strategy to your `Gemfile`:
|
10
|
+
|
11
|
+
gem 'omniauth-angellist'
|
12
|
+
|
13
|
+
You can pull them in directly from github e.g.:
|
14
|
+
|
15
|
+
gem 'omniauth-angellist', :git => 'https://github.com/wasabit/omniauth-angellist.git'
|
16
|
+
|
17
|
+
Once these are in, you need to add the following to your `config/initializers/omniauth.rb`:
|
18
|
+
|
19
|
+
Rails.application.config.middleware.use OmniAuth::Builder do
|
20
|
+
provider :angellist, "consumer_key", "consumer_secret"
|
21
|
+
end
|
22
|
+
|
23
|
+
You will obviously have to put in your key and secret, which you get when you register your app with AngelList (they call them API Key and Secret Key).
|
24
|
+
|
25
|
+
Now just follow the README at: https://github.com/intridea/omniauth
|
26
|
+
|
27
|
+
## License
|
28
|
+
|
29
|
+
Copyright (c) 2012 by Sebastian Rabuini
|
30
|
+
|
31
|
+
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:
|
32
|
+
|
33
|
+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
34
|
+
|
35
|
+
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.
|
data/Rakefile
ADDED
data/lib/..rb
ADDED
@@ -0,0 +1,43 @@
|
|
1
|
+
require 'omniauth-oauth2'
|
2
|
+
|
3
|
+
module OmniAuth
|
4
|
+
module Strategies
|
5
|
+
class AngelList < OmniAuth::Strategies::OAuth2
|
6
|
+
option :client_options, {
|
7
|
+
:site => 'https://angel.co/',
|
8
|
+
:authorize_url => 'https://angel.co/api/oauth/authorize',
|
9
|
+
:token_url => 'https://angel.co/api/oauth/token'
|
10
|
+
}
|
11
|
+
|
12
|
+
def request_phase
|
13
|
+
super
|
14
|
+
end
|
15
|
+
|
16
|
+
uid { raw_ifno['id'] }
|
17
|
+
|
18
|
+
info do
|
19
|
+
{
|
20
|
+
"name" => raw_ifno["name"],
|
21
|
+
"bio" => raw_ifno["bio"],
|
22
|
+
"blog_url" => raw_ifno["blog_url"],
|
23
|
+
"online_bio_url" => raw_ifno["online_bio_url"],
|
24
|
+
"twitter_url" => raw_ifno["twitter_url"],
|
25
|
+
"facebook_url" => raw_ifno["facebook_url"],
|
26
|
+
"linkedin_url" => raw_ifno["linkedin_url"],
|
27
|
+
"follower_count" => raw_ifno["follower_count"],
|
28
|
+
"angellist_url" => raw_ifno["angellist_url"],
|
29
|
+
"image" => raw_ifno["image"],
|
30
|
+
"locations" => raw_ifno["locations"],
|
31
|
+
"roles" => raw_ifno["roles"]
|
32
|
+
}
|
33
|
+
end
|
34
|
+
|
35
|
+
def raw_ifno
|
36
|
+
access_token.options[:mode] = :query
|
37
|
+
@raw_ifno ||= access_token.get('https://api.angel.co/1/me').parsed
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
OmniAuth.config.add_camelization 'angellist', 'AngelList'
|
@@ -0,0 +1,27 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
$:.push File.expand_path("../lib", __FILE__)
|
3
|
+
require "omniauth-angellist/version"
|
4
|
+
|
5
|
+
Gem::Specification.new do |s|
|
6
|
+
s.name = "omniauth-angellist"
|
7
|
+
s.version = Omniauth::AngelList::VERSION
|
8
|
+
s.authors = ["Sebastian Rabuini"]
|
9
|
+
s.email = ["srabuini@gmail.com"]
|
10
|
+
s.homepage = "https://github.com/wasabit/omniauth-angellist"
|
11
|
+
s.summary = %q{AngelList OAuth strategy for OmniAuth}
|
12
|
+
s.description = %q{AngelList OAuth strategy for OmniAuth}
|
13
|
+
|
14
|
+
s.rubyforge_project = "omniauth-angellist"
|
15
|
+
|
16
|
+
s.files = `git ls-files`.split("\n")
|
17
|
+
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
18
|
+
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
19
|
+
s.require_paths = ["lib"]
|
20
|
+
|
21
|
+
s.add_dependency 'omniauth', '~> 1.0'
|
22
|
+
s.add_dependency 'omniauth-oauth2', '~> 1.0'
|
23
|
+
s.add_development_dependency 'rspec', '~> 2.7'
|
24
|
+
s.add_development_dependency 'rack-test'
|
25
|
+
s.add_development_dependency 'simplecov'
|
26
|
+
s.add_development_dependency 'webmock'
|
27
|
+
end
|
@@ -0,0 +1,112 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'omniauth-angellist'
|
3
|
+
|
4
|
+
describe OmniAuth::Strategies::AngelList do
|
5
|
+
before :each do
|
6
|
+
@request = double('Request')
|
7
|
+
@request.stub(:params) { {} }
|
8
|
+
end
|
9
|
+
|
10
|
+
subject do
|
11
|
+
OmniAuth::Strategies::AngelList.new(nil, @options || {}).tap do |strategy|
|
12
|
+
strategy.stub(:request) { @request }
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
it_should_behave_like 'an oauth2 strategy'
|
17
|
+
|
18
|
+
describe '#client' do
|
19
|
+
it 'has correct AngelList site' do
|
20
|
+
subject.client.site.should eq('https://angel.co/')
|
21
|
+
end
|
22
|
+
|
23
|
+
it 'has correct authorize url' do
|
24
|
+
subject.client.options[:authorize_url].should eq('https://angel.co/api/oauth/authorize')
|
25
|
+
end
|
26
|
+
|
27
|
+
it 'has correct token url' do
|
28
|
+
subject.client.options[:token_url].should eq('https://angel.co/api/oauth/token')
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
describe '#info' do
|
33
|
+
before :each do
|
34
|
+
@raw_info = {
|
35
|
+
'name' => 'Sebastian Rabuini',
|
36
|
+
'bio' => 'Sebas',
|
37
|
+
'image' => 'foto',
|
38
|
+
}
|
39
|
+
subject.stub(:raw_ifno) { @raw_info }
|
40
|
+
end
|
41
|
+
|
42
|
+
context 'when data is present in raw info' do
|
43
|
+
it 'returns the combined name' do
|
44
|
+
subject.info['name'].should eq('Sebastian Rabuini')
|
45
|
+
end
|
46
|
+
|
47
|
+
it 'returns the bio' do
|
48
|
+
subject.info['bio'].should eq('Sebas')
|
49
|
+
end
|
50
|
+
|
51
|
+
it 'returns the image' do
|
52
|
+
subject.info['image'].should eq('foto')
|
53
|
+
end
|
54
|
+
|
55
|
+
it "sets the email blank if contact block is missing in raw_info" do
|
56
|
+
@raw_info.delete('contact')
|
57
|
+
subject.info['email'].should be_nil
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
describe '#credentials' do
|
63
|
+
before :each do
|
64
|
+
@access_token = double('OAuth2::AccessToken')
|
65
|
+
@access_token.stub(:token)
|
66
|
+
@access_token.stub(:expires?)
|
67
|
+
@access_token.stub(:expires_at)
|
68
|
+
@access_token.stub(:refresh_token)
|
69
|
+
subject.stub(:access_token) { @access_token }
|
70
|
+
end
|
71
|
+
|
72
|
+
it 'returns a Hash' do
|
73
|
+
subject.credentials.should be_a(Hash)
|
74
|
+
end
|
75
|
+
|
76
|
+
it 'returns the token' do
|
77
|
+
@access_token.stub(:token) { '123' }
|
78
|
+
subject.credentials['token'].should eq('123')
|
79
|
+
end
|
80
|
+
|
81
|
+
it 'returns the expiry status' do
|
82
|
+
@access_token.stub(:expires?) { true }
|
83
|
+
subject.credentials['expires'].should eq(true)
|
84
|
+
|
85
|
+
@access_token.stub(:expires?) { false }
|
86
|
+
subject.credentials['expires'].should eq(false)
|
87
|
+
end
|
88
|
+
|
89
|
+
it 'returns the refresh token and expiry time when expiring' do
|
90
|
+
ten_mins_from_now = (Time.now + 360).to_i
|
91
|
+
@access_token.stub(:expires?) { true }
|
92
|
+
@access_token.stub(:refresh_token) { '321' }
|
93
|
+
@access_token.stub(:expires_at) { ten_mins_from_now }
|
94
|
+
subject.credentials['refresh_token'].should eq('321')
|
95
|
+
subject.credentials['expires_at'].should eq(ten_mins_from_now)
|
96
|
+
end
|
97
|
+
|
98
|
+
it 'does not return the refresh token when it is nil and expiring' do
|
99
|
+
@access_token.stub(:expires?) { true }
|
100
|
+
@access_token.stub(:refresh_token) { nil }
|
101
|
+
subject.credentials['refresh_token'].should be_nil
|
102
|
+
subject.credentials.should_not have_key('refresh_token')
|
103
|
+
end
|
104
|
+
|
105
|
+
it 'does not return the refresh token when not expiring' do
|
106
|
+
@access_token.stub(:expires?) { false }
|
107
|
+
@access_token.stub(:refresh_token) { 'XXX' }
|
108
|
+
subject.credentials['refresh_token'].should be_nil
|
109
|
+
subject.credentials.should_not have_key('refresh_token')
|
110
|
+
end
|
111
|
+
end
|
112
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,37 @@
|
|
1
|
+
# NOTE it would be useful if this lived in omniauth-oauth2 eventually
|
2
|
+
shared_examples 'an oauth2 strategy' do
|
3
|
+
describe '#client' do
|
4
|
+
it 'should be initialized with symbolized client_options' do
|
5
|
+
@options = { :client_options => { 'authorize_url' => 'https://example.com' } }
|
6
|
+
subject.client.options[:authorize_url].should == 'https://example.com'
|
7
|
+
end
|
8
|
+
end
|
9
|
+
|
10
|
+
describe '#authorize_params' do
|
11
|
+
it 'should include any authorize params passed in the :authorize_params option' do
|
12
|
+
@options = { :authorize_params => { :foo => 'bar', :baz => 'zip' } }
|
13
|
+
subject.authorize_params['foo'].should eq('bar')
|
14
|
+
subject.authorize_params['baz'].should eq('zip')
|
15
|
+
end
|
16
|
+
|
17
|
+
it 'should include top-level options that are marked as :authorize_options' do
|
18
|
+
@options = { :authorize_options => [:scope, :foo], :scope => 'bar', :foo => 'baz' }
|
19
|
+
subject.authorize_params['scope'].should eq('bar')
|
20
|
+
subject.authorize_params['foo'].should eq('baz')
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
describe '#token_params' do
|
25
|
+
it 'should include any authorize params passed in the :authorize_params option' do
|
26
|
+
@options = { :token_params => { :foo => 'bar', :baz => 'zip' } }
|
27
|
+
subject.token_params['foo'].should eq('bar')
|
28
|
+
subject.token_params['baz'].should eq('zip')
|
29
|
+
end
|
30
|
+
|
31
|
+
it 'should include top-level options that are marked as :authorize_options' do
|
32
|
+
@options = { :token_options => [:scope, :foo], :scope => 'bar', :foo => 'baz' }
|
33
|
+
subject.token_params['scope'].should eq('bar')
|
34
|
+
subject.token_params['foo'].should eq('baz')
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
metadata
ADDED
@@ -0,0 +1,157 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: omniauth-angellist
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Sebastian Rabuini
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2012-08-13 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: omniauth
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ~>
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '1.0'
|
22
|
+
type: :runtime
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ~>
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '1.0'
|
30
|
+
- !ruby/object:Gem::Dependency
|
31
|
+
name: omniauth-oauth2
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
33
|
+
none: false
|
34
|
+
requirements:
|
35
|
+
- - ~>
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: '1.0'
|
38
|
+
type: :runtime
|
39
|
+
prerelease: false
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ~>
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: '1.0'
|
46
|
+
- !ruby/object:Gem::Dependency
|
47
|
+
name: rspec
|
48
|
+
requirement: !ruby/object:Gem::Requirement
|
49
|
+
none: false
|
50
|
+
requirements:
|
51
|
+
- - ~>
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: '2.7'
|
54
|
+
type: :development
|
55
|
+
prerelease: false
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
57
|
+
none: false
|
58
|
+
requirements:
|
59
|
+
- - ~>
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '2.7'
|
62
|
+
- !ruby/object:Gem::Dependency
|
63
|
+
name: rack-test
|
64
|
+
requirement: !ruby/object:Gem::Requirement
|
65
|
+
none: false
|
66
|
+
requirements:
|
67
|
+
- - ! '>='
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: '0'
|
70
|
+
type: :development
|
71
|
+
prerelease: false
|
72
|
+
version_requirements: !ruby/object:Gem::Requirement
|
73
|
+
none: false
|
74
|
+
requirements:
|
75
|
+
- - ! '>='
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
version: '0'
|
78
|
+
- !ruby/object:Gem::Dependency
|
79
|
+
name: simplecov
|
80
|
+
requirement: !ruby/object:Gem::Requirement
|
81
|
+
none: false
|
82
|
+
requirements:
|
83
|
+
- - ! '>='
|
84
|
+
- !ruby/object:Gem::Version
|
85
|
+
version: '0'
|
86
|
+
type: :development
|
87
|
+
prerelease: false
|
88
|
+
version_requirements: !ruby/object:Gem::Requirement
|
89
|
+
none: false
|
90
|
+
requirements:
|
91
|
+
- - ! '>='
|
92
|
+
- !ruby/object:Gem::Version
|
93
|
+
version: '0'
|
94
|
+
- !ruby/object:Gem::Dependency
|
95
|
+
name: webmock
|
96
|
+
requirement: !ruby/object:Gem::Requirement
|
97
|
+
none: false
|
98
|
+
requirements:
|
99
|
+
- - ! '>='
|
100
|
+
- !ruby/object:Gem::Version
|
101
|
+
version: '0'
|
102
|
+
type: :development
|
103
|
+
prerelease: false
|
104
|
+
version_requirements: !ruby/object:Gem::Requirement
|
105
|
+
none: false
|
106
|
+
requirements:
|
107
|
+
- - ! '>='
|
108
|
+
- !ruby/object:Gem::Version
|
109
|
+
version: '0'
|
110
|
+
description: AngelList OAuth strategy for OmniAuth
|
111
|
+
email:
|
112
|
+
- srabuini@gmail.com
|
113
|
+
executables: []
|
114
|
+
extensions: []
|
115
|
+
extra_rdoc_files: []
|
116
|
+
files:
|
117
|
+
- ..gemspec
|
118
|
+
- .gitignore
|
119
|
+
- Gemfile
|
120
|
+
- README.md
|
121
|
+
- Rakefile
|
122
|
+
- lib/..rb
|
123
|
+
- lib/omniauth-angellist.rb
|
124
|
+
- lib/omniauth-angellist/version.rb
|
125
|
+
- lib/omniauth/strategies/angellist.rb
|
126
|
+
- omniauth-angellist.gemspec
|
127
|
+
- spec/omniauth/strategies/angellist_spec.rb
|
128
|
+
- spec/spec_helper.rb
|
129
|
+
- spec/support/shared_examples.rb
|
130
|
+
homepage: https://github.com/wasabit/omniauth-angellist
|
131
|
+
licenses: []
|
132
|
+
post_install_message:
|
133
|
+
rdoc_options: []
|
134
|
+
require_paths:
|
135
|
+
- lib
|
136
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
137
|
+
none: false
|
138
|
+
requirements:
|
139
|
+
- - ! '>='
|
140
|
+
- !ruby/object:Gem::Version
|
141
|
+
version: '0'
|
142
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
143
|
+
none: false
|
144
|
+
requirements:
|
145
|
+
- - ! '>='
|
146
|
+
- !ruby/object:Gem::Version
|
147
|
+
version: '0'
|
148
|
+
requirements: []
|
149
|
+
rubyforge_project: omniauth-angellist
|
150
|
+
rubygems_version: 1.8.23
|
151
|
+
signing_key:
|
152
|
+
specification_version: 3
|
153
|
+
summary: AngelList OAuth strategy for OmniAuth
|
154
|
+
test_files:
|
155
|
+
- spec/omniauth/strategies/angellist_spec.rb
|
156
|
+
- spec/spec_helper.rb
|
157
|
+
- spec/support/shared_examples.rb
|