omniauth-github-discourse 1.1.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 2c93aa199b625b6a23d3d9e1a6dd74d96b991d48
4
+ data.tar.gz: a0ea9f019169c46d64c8197a705fcffd2accad49
5
+ SHA512:
6
+ metadata.gz: ded7688c97abd9ab8f0cbe29667f9b3157738007b596878a5d9515511aa63af32e77272ca9bb989124633aa9cd11b7d0d1a93fc89e57ffbf7f034824fd4e932f
7
+ data.tar.gz: 74c4e8f1d29bb63b43fc38dfcd5db16fe653bb68a75702cedc93b09381e7f88b76a7e56576b3279636ca009069fea84a9bf8b9b194710a6879855d0d877e18fb
@@ -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,13 @@
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 'rake'
8
+ gem 'guard'
9
+ gem 'guard-rspec'
10
+ gem 'guard-bundler'
11
+ gem 'rb-fsevent'
12
+ gem 'growl'
13
+ 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,42 @@
1
+ # OmniAuth GitHub
2
+
3
+ This is the official OmniAuth strategy for authenticating to GitHub. To
4
+ use it, you'll need to sign up for an OAuth2 Application ID and Secret
5
+ on the [GitHub Applications Page](https://github.com/settings/applications).
6
+
7
+ ## Basic Usage
8
+
9
+ use OmniAuth::Builder do
10
+ provider :github, ENV['GITHUB_KEY'], ENV['GITHUB_SECRET']
11
+ end
12
+
13
+ ## Github Enterprise Usage
14
+
15
+ provider :github, ENV['GITHUB_KEY'], ENV['GITHUB_SECRET'],
16
+ {
17
+ :client_options => {
18
+ :site => 'https://github.YOURDOMAIN.com/api/v3',
19
+ :authorize_url => 'https://github.YOURDOMAIN.com/login/oauth/authorize',
20
+ :token_url => 'https://github.YOURDOMAIN.com/login/oauth/access_token',
21
+ }
22
+ }
23
+
24
+ ## Scopes
25
+
26
+ GitHub API v3 lets you set scopes to provide granular access to different types of data:
27
+
28
+ use OmniAuth::Builder do
29
+ provider :github, ENV['GITHUB_KEY'], ENV['GITHUB_SECRET'], scope: "user,repo,gist"
30
+ end
31
+
32
+ More info on [Scopes](http://developer.github.com/v3/oauth/#scopes).
33
+
34
+ ## License
35
+
36
+ Copyright (c) 2011 Michael Bleigh and Intridea, Inc.
37
+
38
+ 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:
39
+
40
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
41
+
42
+ 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,8 @@
1
+ #!/usr/bin/env rake
2
+ require "bundler/gem_tasks"
3
+ require 'rspec/core/rake_task'
4
+
5
+ RSpec::Core::RakeTask.new
6
+
7
+ desc 'Run specs'
8
+ 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.1.2"
4
+ end
5
+ end
@@ -0,0 +1,80 @@
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
+ def authorize_params
17
+ super.tap do |params|
18
+ %w[scope client_options].each do |v|
19
+ if request.params[v]
20
+ params[v.to_sym] = request.params[v]
21
+ end
22
+ end
23
+ end
24
+ end
25
+
26
+ uid { raw_info['id'].to_s }
27
+
28
+ info do
29
+ {
30
+ 'nickname' => raw_info['login'],
31
+ 'email' => email,
32
+ 'email_verified' => @email_verified || false,
33
+ 'display_email' => raw_info['email'],
34
+ 'name' => raw_info['name'],
35
+ 'image' => raw_info['avatar_url'],
36
+ 'urls' => {
37
+ 'GitHub' => "https://github.com/#{raw_info['login']}",
38
+ 'Blog' => raw_info['blog'],
39
+ },
40
+ }
41
+ end
42
+
43
+ extra do
44
+ {:raw_info => raw_info, :all_emails => emails}
45
+ end
46
+
47
+ def raw_info
48
+ access_token.options[:mode] = :query
49
+ @raw_info ||= access_token.get('user').parsed
50
+ end
51
+
52
+ def email
53
+ (email_access_allowed?) ? primary_email : raw_info['email']
54
+ end
55
+
56
+ def primary_email
57
+ primary = emails.find { |i| i['primary'] }
58
+ if primary && primary['email']
59
+ @email_verified = primary['verified']
60
+ return primary['email']
61
+ end
62
+ emails.first && emails.first['email']
63
+ end
64
+
65
+ # The new /user/emails API - http://developer.github.com/v3/users/emails/#future-response
66
+ def emails
67
+ return [] unless email_access_allowed?
68
+ access_token.options[:mode] = :query
69
+ @emails ||= access_token.get('user/emails', :headers => { 'Accept' => 'application/vnd.github.v3' }).parsed
70
+ end
71
+
72
+ def email_access_allowed?
73
+ options['scope'] =~ /user/
74
+ end
75
+
76
+ end
77
+ end
78
+ end
79
+
80
+ 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"]
6
+ gem.email = ["michael@intridea.com"]
7
+ gem.description = %q{Temporary Fork of Official OmniAuth strategy for GitHub.}
8
+ gem.summary = %q{Temporary Fork of Official OmniAuth strategy for GitHub.}
9
+ gem.homepage = "https://github.com/intridea/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 = "omniauth-github-discourse"
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,135 @@
1
+ require 'spec_helper'
2
+
3
+ describe OmniAuth::Strategies::GitHub do
4
+ let(:access_token) { stub('AccessToken', :options => {}) }
5
+ let(:parsed_response) { stub('ParsedResponse') }
6
+ let(:response) { stub('Response', :parsed => parsed_response) }
7
+
8
+ let(:enterprise_site) { 'https://some.other.site.com/api/v3' }
9
+ let(:enterprise_authorize_url) { 'https://some.other.site.com/login/oauth/authorize' }
10
+ let(:enterprise_token_url) { 'https://some.other.site.com/login/oauth/access_token' }
11
+ let(:enterprise) do
12
+ OmniAuth::Strategies::GitHub.new('GITHUB_KEY', 'GITHUB_SECRET',
13
+ {
14
+ :client_options => {
15
+ :site => enterprise_site,
16
+ :authorize_url => enterprise_authorize_url,
17
+ :token_url => enterprise_token_url
18
+ }
19
+ }
20
+ )
21
+ end
22
+
23
+ subject do
24
+ OmniAuth::Strategies::GitHub.new({})
25
+ end
26
+
27
+ before(:each) do
28
+ subject.stub!(:access_token).and_return(access_token)
29
+ end
30
+
31
+ context "client options" do
32
+ it 'should have correct site' do
33
+ subject.options.client_options.site.should eq("https://api.github.com")
34
+ end
35
+
36
+ it 'should have correct authorize url' do
37
+ subject.options.client_options.authorize_url.should eq('https://github.com/login/oauth/authorize')
38
+ end
39
+
40
+ it 'should have correct token url' do
41
+ subject.options.client_options.token_url.should eq('https://github.com/login/oauth/access_token')
42
+ end
43
+
44
+ describe "should be overrideable" do
45
+ it "for site" do
46
+ enterprise.options.client_options.site.should eq(enterprise_site)
47
+ end
48
+
49
+ it "for authorize url" do
50
+ enterprise.options.client_options.authorize_url.should eq(enterprise_authorize_url)
51
+ end
52
+
53
+ it "for token url" do
54
+ enterprise.options.client_options.token_url.should eq(enterprise_token_url)
55
+ end
56
+ end
57
+ end
58
+
59
+ context "#email_access_allowed?" do
60
+ it "should not allow email if scope is nil" do
61
+ subject.options['scope'].should be_nil
62
+ subject.should_not be_email_access_allowed
63
+ end
64
+
65
+ it "should allow email if scope is user" do
66
+ subject.options['scope'] = 'user'
67
+ subject.should be_email_access_allowed
68
+ end
69
+
70
+ it "should allow email if scope is a bunch of stuff including user" do
71
+ subject.options['scope'] = 'public_repo,user,repo,delete_repo,gist'
72
+ subject.should be_email_access_allowed
73
+ end
74
+
75
+ it "should not allow email if scope is other than user" do
76
+ subject.options['scope'] = 'repo'
77
+ subject.should_not be_email_access_allowed
78
+ end
79
+
80
+ it "should assume email access not allowed if scope is something currently not documented " do
81
+ subject.options['scope'] = 'currently_not_documented'
82
+ subject.should_not be_email_access_allowed
83
+ end
84
+ end
85
+
86
+ context "#email" do
87
+ it "should return email from raw_info if available" do
88
+ subject.stub!(:raw_info).and_return({'email' => 'you@example.com'})
89
+ subject.email.should eq('you@example.com')
90
+ end
91
+
92
+ it "should return nil if there is no raw_info and email access is not allowed" do
93
+ subject.stub!(:raw_info).and_return({})
94
+ subject.email.should be_nil
95
+ end
96
+
97
+ it "should return the primary email if there is no raw_info and email access is allowed" do
98
+ emails = [
99
+ { 'email' => 'secondary@example.com', 'primary' => false },
100
+ { 'email' => 'primary@example.com', 'primary' => true }
101
+ ]
102
+ subject.stub!(:raw_info).and_return({})
103
+ subject.options['scope'] = 'user'
104
+ subject.stub!(:emails).and_return(emails)
105
+ subject.email.should eq('primary@example.com')
106
+ end
107
+
108
+ it "should return the first email if there is no raw_info and email access is allowed" do
109
+ emails = [
110
+ { 'email' => 'first@example.com', 'primary' => false },
111
+ { 'email' => 'second@example.com', 'primary' => false }
112
+ ]
113
+ subject.stub!(:raw_info).and_return({})
114
+ subject.options['scope'] = 'user'
115
+ subject.stub!(:emails).and_return(emails)
116
+ subject.email.should eq('first@example.com')
117
+ end
118
+ end
119
+
120
+ context "#raw_info" do
121
+ it "should use relative paths" do
122
+ access_token.should_receive(:get).with('user').and_return(response)
123
+ subject.raw_info.should eq(parsed_response)
124
+ end
125
+ end
126
+
127
+ context "#emails" do
128
+ it "should use relative paths" do
129
+ access_token.should_receive(:get).with('user/emails', :headers=>{"Accept"=>"application/vnd.github.v3"}).and_return(response)
130
+ subject.options['scope'] = 'user'
131
+ subject.emails.should eq(parsed_response)
132
+ end
133
+ end
134
+
135
+ 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,139 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: omniauth-github-discourse
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.1.2
5
+ platform: ruby
6
+ authors:
7
+ - Michael Bleigh
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-09-03 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: omniauth
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: omniauth-oauth2
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '1.1'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.1'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '2.7'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '2.7'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rack-test
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: simplecov
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: webmock
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ description: Temporary Fork of Official OmniAuth strategy for GitHub.
98
+ email:
99
+ - michael@intridea.com
100
+ executables: []
101
+ extensions: []
102
+ extra_rdoc_files: []
103
+ files:
104
+ - ".gitignore"
105
+ - ".rspec"
106
+ - Gemfile
107
+ - Guardfile
108
+ - README.md
109
+ - Rakefile
110
+ - lib/omniauth-github.rb
111
+ - lib/omniauth-github/version.rb
112
+ - lib/omniauth/strategies/github.rb
113
+ - omniauth-github.gemspec
114
+ - spec/omniauth/strategies/github_spec.rb
115
+ - spec/spec_helper.rb
116
+ homepage: https://github.com/intridea/omniauth-github
117
+ licenses: []
118
+ metadata: {}
119
+ post_install_message:
120
+ rdoc_options: []
121
+ require_paths:
122
+ - lib
123
+ required_ruby_version: !ruby/object:Gem::Requirement
124
+ requirements:
125
+ - - ">="
126
+ - !ruby/object:Gem::Version
127
+ version: '0'
128
+ required_rubygems_version: !ruby/object:Gem::Requirement
129
+ requirements:
130
+ - - ">="
131
+ - !ruby/object:Gem::Version
132
+ version: '0'
133
+ requirements: []
134
+ rubyforge_project:
135
+ rubygems_version: 2.2.2
136
+ signing_key:
137
+ specification_version: 4
138
+ summary: Temporary Fork of Official OmniAuth strategy for GitHub.
139
+ test_files: []