crowdint_omniauth-github 1.0.2.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ /pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/.rspec ADDED
@@ -0,0 +1 @@
1
+ --colour
data/Gemfile ADDED
@@ -0,0 +1,12 @@
1
+ source 'http://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in omniauth-github.gemspec
4
+ gemspec
5
+
6
+ group :development, :test do
7
+ gem 'guard'
8
+ gem 'guard-rspec'
9
+ gem 'guard-bundler'
10
+ gem 'rb-fsevent'
11
+ gem 'growl'
12
+ end
@@ -0,0 +1,10 @@
1
+ guard 'rspec', :version => 2 do
2
+ watch(%r{^spec/.+_spec\.rb$})
3
+ watch(%r{^lib/(.+)\.rb$}) { |m| "spec/#{m[1]}_spec.rb" }
4
+ watch('spec/spec_helper.rb') { "spec" }
5
+ end
6
+
7
+ guard 'bundler' do
8
+ watch('Gemfile')
9
+ watch('omniauth-github.gemspec')
10
+ end
@@ -0,0 +1,40 @@
1
+ # Temporary repository!
2
+
3
+ This only fixes the bug when the scope is nil or :public as reported in:
4
+ <https://github.com/intridea/omniauth-github/pull/13>
5
+
6
+ The only purpose of this repository is to create a temporary gem:
7
+ <http://rubygems.org/gems/crowdint_omniauth-github>
8
+
9
+
10
+ # OmniAuth GitHub
11
+
12
+ This is the official OmniAuth strategy for authenticating to GitHub. To
13
+ use it, you'll need to sign up for an OAuth2 Application ID and Secret
14
+ on the [GitHub Applications Page](https://github.com/settings/applications).
15
+
16
+ ## Basic Usage
17
+
18
+ use OmniAuth::Builder do
19
+ provider :github, ENV['GITHUB_KEY'], ENV['GITHUB_SECRET']
20
+ end
21
+
22
+ ### Scopes
23
+
24
+ GitHub API v3 lets you set scopes to provide granular access to different types of data:
25
+
26
+ use OmniAuth::Builder do
27
+ provider :github, ENV['GITHUB_KEY'], ENV['GITHUB_SECRET'], scope: "user,repo,gist"
28
+ end
29
+
30
+ More info on [Scopes](http://developer.github.com/v3/oauth/#scopes).
31
+
32
+ ## License
33
+
34
+ Copyright (c) 2011 Michael Bleigh and Intridea, Inc.
35
+
36
+ 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:
37
+
38
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
39
+
40
+ 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,12 @@
1
+ #!/usr/bin/env rake
2
+ require "bundler/gem_tasks"
3
+ require 'rspec/core/rake_task'
4
+
5
+ desc 'Default: run specs.'
6
+ task :default => :spec
7
+
8
+ desc "Run specs"
9
+ RSpec::Core::RakeTask.new
10
+
11
+ desc 'Run specs'
12
+ task :default => :spec
@@ -0,0 +1,2 @@
1
+ require "omniauth-github/version"
2
+ require 'omniauth/strategies/github'
@@ -0,0 +1,5 @@
1
+ module OmniAuth
2
+ module GitHub
3
+ VERSION = "1.0.2.1"
4
+ end
5
+ end
@@ -0,0 +1,57 @@
1
+ require 'omniauth-oauth2'
2
+
3
+ module OmniAuth
4
+ module Strategies
5
+ class GitHub < OmniAuth::Strategies::OAuth2
6
+ option :client_options, {
7
+ :site => 'https://api.github.com',
8
+ :authorize_url => 'https://github.com/login/oauth/authorize',
9
+ :token_url => 'https://github.com/login/oauth/access_token'
10
+ }
11
+
12
+ def request_phase
13
+ super
14
+ end
15
+
16
+ uid { raw_info['id'] }
17
+
18
+ info do
19
+ {
20
+ 'nickname' => raw_info['login'],
21
+ 'email' => email,
22
+ 'name' => raw_info['name'],
23
+ 'image' => raw_info['avatar_url'],
24
+ 'urls' => {
25
+ 'GitHub' => "https://github.com/#{raw_info['login']}",
26
+ 'Blog' => raw_info['blog'],
27
+ },
28
+ }
29
+ end
30
+
31
+ extra do
32
+ {:raw_info => raw_info}
33
+ end
34
+
35
+ def raw_info
36
+ access_token.options[:mode] = :query
37
+ @raw_info ||= access_token.get('/user').parsed
38
+ end
39
+
40
+ def email
41
+ raw_info['email'] || (email_access_allowed? ? emails.first : nil)
42
+ end
43
+
44
+ def emails
45
+ access_token.options[:mode] = :query
46
+ @emails ||= access_token.get('/user/emails').parsed
47
+ end
48
+
49
+ def email_access_allowed?
50
+ options['scope'] && !(options['scope'] == 'public')
51
+ end
52
+
53
+ end
54
+ end
55
+ end
56
+
57
+ OmniAuth.config.add_camelization 'github', 'GitHub'
@@ -0,0 +1,24 @@
1
+ # -*- encoding: utf-8 -*-
2
+ require File.expand_path('../lib/omniauth-github/version', __FILE__)
3
+
4
+ Gem::Specification.new do |gem|
5
+ gem.authors = ["Michael Bleigh", 'Ian Goodrich', 'Crowd Interactive']
6
+ gem.email = ["michael@intridea.com", 'opensource@crowdint.com']
7
+ gem.description = %q{Fixes scope: nil >> Official GitHub strategy for OmniAuth.}
8
+ gem.summary = %q{Fixes scope: nil >> Official GitHub strategy for OmniAuth .}
9
+ gem.homepage = "https://github.com/crowdint/omniauth-github"
10
+
11
+ gem.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
12
+ gem.files = `git ls-files`.split("\n")
13
+ gem.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
14
+ gem.name = "crowdint_omniauth-github"
15
+ gem.require_paths = ["lib"]
16
+ gem.version = OmniAuth::GitHub::VERSION
17
+
18
+ gem.add_dependency 'omniauth', '~> 1.0'
19
+ gem.add_dependency 'omniauth-oauth2', '~> 1.1'
20
+ gem.add_development_dependency 'rspec', '~> 2.7'
21
+ gem.add_development_dependency 'rack-test'
22
+ gem.add_development_dependency 'simplecov'
23
+ gem.add_development_dependency 'webmock'
24
+ end
@@ -0,0 +1,68 @@
1
+ require 'spec_helper'
2
+
3
+ describe OmniAuth::Strategies::GitHub do
4
+ subject do
5
+ OmniAuth::Strategies::GitHub.new({})
6
+ end
7
+
8
+ context "client options" do
9
+ it 'should have correct site' do
10
+ subject.options.client_options.site.should eq("https://api.github.com")
11
+ end
12
+
13
+ it 'should have correct authorize url' do
14
+ subject.options.client_options.authorize_url.should eq('https://github.com/login/oauth/authorize')
15
+ end
16
+
17
+ it 'should have correct token url' do
18
+ subject.options.client_options.token_url.should eq('https://github.com/login/oauth/access_token')
19
+ end
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
+
68
+ end
@@ -0,0 +1,16 @@
1
+ $:.unshift File.expand_path('..', __FILE__)
2
+ $:.unshift File.expand_path('../../lib', __FILE__)
3
+ require 'simplecov'
4
+ SimpleCov.start
5
+ require 'rspec'
6
+ require 'rack/test'
7
+ require 'webmock/rspec'
8
+ require 'omniauth'
9
+ require 'omniauth-github'
10
+
11
+ RSpec.configure do |config|
12
+ config.include WebMock::API
13
+ config.include Rack::Test::Methods
14
+ config.extend OmniAuth::Test::StrategyMacros, :type => :strategy
15
+ end
16
+
metadata ADDED
@@ -0,0 +1,158 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: crowdint_omniauth-github
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.2.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Michael Bleigh
9
+ - Ian Goodrich
10
+ - Crowd Interactive
11
+ autorequire:
12
+ bindir: bin
13
+ cert_chain: []
14
+ date: 2012-08-15 00:00:00.000000000 Z
15
+ dependencies:
16
+ - !ruby/object:Gem::Dependency
17
+ name: omniauth
18
+ requirement: !ruby/object:Gem::Requirement
19
+ none: false
20
+ requirements:
21
+ - - ~>
22
+ - !ruby/object:Gem::Version
23
+ version: '1.0'
24
+ type: :runtime
25
+ prerelease: false
26
+ version_requirements: !ruby/object:Gem::Requirement
27
+ none: false
28
+ requirements:
29
+ - - ~>
30
+ - !ruby/object:Gem::Version
31
+ version: '1.0'
32
+ - !ruby/object:Gem::Dependency
33
+ name: omniauth-oauth2
34
+ requirement: !ruby/object:Gem::Requirement
35
+ none: false
36
+ requirements:
37
+ - - ~>
38
+ - !ruby/object:Gem::Version
39
+ version: '1.1'
40
+ type: :runtime
41
+ prerelease: false
42
+ version_requirements: !ruby/object:Gem::Requirement
43
+ none: false
44
+ requirements:
45
+ - - ~>
46
+ - !ruby/object:Gem::Version
47
+ version: '1.1'
48
+ - !ruby/object:Gem::Dependency
49
+ name: rspec
50
+ requirement: !ruby/object:Gem::Requirement
51
+ none: false
52
+ requirements:
53
+ - - ~>
54
+ - !ruby/object:Gem::Version
55
+ version: '2.7'
56
+ type: :development
57
+ prerelease: false
58
+ version_requirements: !ruby/object:Gem::Requirement
59
+ none: false
60
+ requirements:
61
+ - - ~>
62
+ - !ruby/object:Gem::Version
63
+ version: '2.7'
64
+ - !ruby/object:Gem::Dependency
65
+ name: rack-test
66
+ requirement: !ruby/object:Gem::Requirement
67
+ none: false
68
+ requirements:
69
+ - - ! '>='
70
+ - !ruby/object:Gem::Version
71
+ version: '0'
72
+ type: :development
73
+ prerelease: false
74
+ version_requirements: !ruby/object:Gem::Requirement
75
+ none: false
76
+ requirements:
77
+ - - ! '>='
78
+ - !ruby/object:Gem::Version
79
+ version: '0'
80
+ - !ruby/object:Gem::Dependency
81
+ name: simplecov
82
+ requirement: !ruby/object:Gem::Requirement
83
+ none: false
84
+ requirements:
85
+ - - ! '>='
86
+ - !ruby/object:Gem::Version
87
+ version: '0'
88
+ type: :development
89
+ prerelease: false
90
+ version_requirements: !ruby/object:Gem::Requirement
91
+ none: false
92
+ requirements:
93
+ - - ! '>='
94
+ - !ruby/object:Gem::Version
95
+ version: '0'
96
+ - !ruby/object:Gem::Dependency
97
+ name: webmock
98
+ requirement: !ruby/object:Gem::Requirement
99
+ none: false
100
+ requirements:
101
+ - - ! '>='
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ none: false
108
+ requirements:
109
+ - - ! '>='
110
+ - !ruby/object:Gem::Version
111
+ version: '0'
112
+ description: ! 'Fixes scope: nil >> Official GitHub strategy for OmniAuth.'
113
+ email:
114
+ - michael@intridea.com
115
+ - opensource@crowdint.com
116
+ executables: []
117
+ extensions: []
118
+ extra_rdoc_files: []
119
+ files:
120
+ - .gitignore
121
+ - .rspec
122
+ - Gemfile
123
+ - Guardfile
124
+ - README.md
125
+ - Rakefile
126
+ - lib/omniauth-github.rb
127
+ - lib/omniauth-github/version.rb
128
+ - lib/omniauth/strategies/github.rb
129
+ - omniauth-github.gemspec
130
+ - spec/omniauth/strategies/github_spec.rb
131
+ - spec/spec_helper.rb
132
+ homepage: https://github.com/crowdint/omniauth-github
133
+ licenses: []
134
+ post_install_message:
135
+ rdoc_options: []
136
+ require_paths:
137
+ - lib
138
+ required_ruby_version: !ruby/object:Gem::Requirement
139
+ none: false
140
+ requirements:
141
+ - - ! '>='
142
+ - !ruby/object:Gem::Version
143
+ version: '0'
144
+ required_rubygems_version: !ruby/object:Gem::Requirement
145
+ none: false
146
+ requirements:
147
+ - - ! '>='
148
+ - !ruby/object:Gem::Version
149
+ version: '0'
150
+ requirements: []
151
+ rubyforge_project:
152
+ rubygems_version: 1.8.23
153
+ signing_key:
154
+ specification_version: 3
155
+ summary: ! 'Fixes scope: nil >> Official GitHub strategy for OmniAuth .'
156
+ test_files:
157
+ - spec/omniauth/strategies/github_spec.rb
158
+ - spec/spec_helper.rb