omniauth-github 1.0.2 → 1.0.3
Sign up to get free protection for your applications and to get access to all the features.
- data/Rakefile +0 -4
- data/lib/omniauth-github/version.rb +1 -1
- data/lib/omniauth/strategies/github.rb +7 -2
- data/spec/omniauth/strategies/github_spec.rb +47 -0
- metadata +2 -2
data/Rakefile
CHANGED
@@ -13,7 +13,7 @@ module OmniAuth
|
|
13
13
|
super
|
14
14
|
end
|
15
15
|
|
16
|
-
uid { raw_info['id'] }
|
16
|
+
uid { raw_info['id'].to_s }
|
17
17
|
|
18
18
|
info do
|
19
19
|
{
|
@@ -38,13 +38,18 @@ module OmniAuth
|
|
38
38
|
end
|
39
39
|
|
40
40
|
def email
|
41
|
-
raw_info['email'] || emails.first
|
41
|
+
raw_info['email'] || (email_access_allowed? ? emails.first : nil)
|
42
42
|
end
|
43
43
|
|
44
44
|
def emails
|
45
45
|
access_token.options[:mode] = :query
|
46
46
|
@emails ||= access_token.get('/user/emails').parsed
|
47
47
|
end
|
48
|
+
|
49
|
+
def email_access_allowed?
|
50
|
+
options['scope'] && !(options['scope'] == 'public')
|
51
|
+
end
|
52
|
+
|
48
53
|
end
|
49
54
|
end
|
50
55
|
end
|
@@ -18,4 +18,51 @@ describe OmniAuth::Strategies::GitHub do
|
|
18
18
|
subject.options.client_options.token_url.should eq('https://github.com/login/oauth/access_token')
|
19
19
|
end
|
20
20
|
end
|
21
|
+
|
22
|
+
context "#email_access_allowed?" do
|
23
|
+
it "should not allow email if scope is nil" do
|
24
|
+
subject.options['scope'].should be_nil
|
25
|
+
subject.should_not be_email_access_allowed
|
26
|
+
end
|
27
|
+
|
28
|
+
it "should not allow email if scope is 'public'" do
|
29
|
+
subject.options['scope'] = 'public'
|
30
|
+
subject.should_not be_email_access_allowed
|
31
|
+
end
|
32
|
+
|
33
|
+
it "should allow email if scope is user" do
|
34
|
+
subject.options['scope'] = 'user'
|
35
|
+
subject.should be_email_access_allowed
|
36
|
+
end
|
37
|
+
|
38
|
+
it "should allow email if scope is scope is a bunch of stuff" do
|
39
|
+
subject.options['scope'] = 'user,public_repo,repo,delete_repo,gist'
|
40
|
+
subject.should be_email_access_allowed
|
41
|
+
end
|
42
|
+
|
43
|
+
it "should assume email access allowed if scope is scope is something currently not documented " do
|
44
|
+
subject.options['scope'] = 'currently_not_documented'
|
45
|
+
subject.should be_email_access_allowed
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
context "#email" do
|
50
|
+
it "should return email from raw_info if available" do
|
51
|
+
subject.stub!(:raw_info).and_return({'email' => 'you@example.com'})
|
52
|
+
subject.email.should eq('you@example.com')
|
53
|
+
end
|
54
|
+
|
55
|
+
it "should return nil if there is no raw_info and email access is not allowed" do
|
56
|
+
subject.stub!(:raw_info).and_return({})
|
57
|
+
subject.email.should be_nil
|
58
|
+
end
|
59
|
+
|
60
|
+
it "should return the first email if there is no raw_info and email access is allowed" do
|
61
|
+
subject.stub!(:raw_info).and_return({})
|
62
|
+
subject.options['scope'] = 'user'
|
63
|
+
subject.stub!(:emails).and_return([ 'you@example.com' ])
|
64
|
+
subject.email.should eq('you@example.com')
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
21
68
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: omniauth-github
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.3
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-
|
12
|
+
date: 2012-08-28 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: omniauth
|