warden-github 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2010 Corey Donohoe
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,10 @@
1
+ warden-github
2
+ =============
3
+
4
+ A sinatra app the provides a gem that...
5
+
6
+ Developing
7
+ ==========
8
+ % gem install bundler
9
+ % bundle install
10
+ % bundle exec rake
data/Rakefile ADDED
@@ -0,0 +1,60 @@
1
+ require 'rake/gempackagetask'
2
+ require 'rubygems/specification'
3
+ require 'date'
4
+ require 'bundler'
5
+
6
+ task :default => [:spec]
7
+
8
+ require 'spec/rake/spectask'
9
+ desc "Run specs"
10
+ Spec::Rake::SpecTask.new do |t|
11
+ t.spec_files = FileList['spec/**/*_spec.rb']
12
+ t.spec_opts = %w(-fs --color)
13
+ t.spec_opts << '--loadby' << 'random'
14
+
15
+ t.rcov_opts << '--exclude' << 'spec,.bundle,.rvm'
16
+ t.rcov = ENV.has_key?('NO_RCOV') ? ENV['NO_RCOV'] != 'true' : true
17
+ t.rcov_opts << '--text-summary'
18
+ t.rcov_opts << '--sort' << 'coverage' << '--sort-reverse'
19
+ end
20
+
21
+ GEM = "warden-github"
22
+ GEM_VERSION = "0.0.1"
23
+ AUTHOR = "Corey Donohoe"
24
+ EMAIL = "atmos@atmos.org"
25
+ HOMEPAGE = "http://github.com/atmos/warden-github"
26
+ SUMMARY = "A warden extension that integrates with github oauth"
27
+
28
+ spec = Gem::Specification.new do |s|
29
+ s.name = GEM
30
+ s.version = GEM_VERSION
31
+ s.platform = Gem::Platform::RUBY
32
+ s.has_rdoc = true
33
+ s.extra_rdoc_files = ["LICENSE"]
34
+ s.summary = SUMMARY
35
+ s.description = s.summary
36
+ s.author = AUTHOR
37
+ s.email = EMAIL
38
+ s.homepage = HOMEPAGE
39
+
40
+ bundle = Bundler::Definition.from_gemfile('Gemfile')
41
+ bundle.dependencies.each do |dep|
42
+ next unless dep.groups.include?(:runtime)
43
+ s.add_dependency(dep.name, dep.version_requirements.to_s)
44
+ end
45
+
46
+ s.require_path = 'lib'
47
+ s.files = %w(LICENSE README.md Rakefile) + Dir.glob("{lib}/**/*")
48
+ end
49
+
50
+ Rake::GemPackageTask.new(spec) do |pkg|
51
+ pkg.gem_spec = spec
52
+ end
53
+
54
+ desc "create a gemspec file"
55
+ task :make_spec do
56
+ File.open("#{GEM}.gemspec", "w") do |file|
57
+ file.puts spec.to_ruby
58
+ end
59
+ end
60
+
@@ -0,0 +1,12 @@
1
+ require 'warden'
2
+ require 'oauth2'
3
+
4
+ module Warden
5
+ module Github
6
+ class GithubMisconfiguredError < StandardError; end
7
+ end
8
+ end
9
+
10
+ require 'warden-github/user'
11
+ require 'warden-github/version'
12
+ require 'warden-github/strategy'
@@ -0,0 +1,48 @@
1
+ Warden::Strategies.add(:github) do
2
+ # Need to make sure that we have a pure representation of the query string.
3
+ # Rails adds an "action" parameter which causes the openid gem to error
4
+ def params
5
+ @params ||= Rack::Utils.parse_query(request.query_string)
6
+ end
7
+
8
+ def authenticate!
9
+ if params['code']
10
+ begin
11
+ access_token = oauth_client.web_server.get_access_token(params['code'], :redirect_uri => callback_url)
12
+ user = JSON.parse(access_token.get('/api/v2/json/user/show'))
13
+ success!(Warden::Github::Oauth::User.new(user['user'], access_token.token))
14
+ rescue OAuth2::HTTPError
15
+ %(<p>Outdated ?code=#{params[:code]}:</p><p>#{$!}</p><p><a href="/auth/github">Retry</a></p>)
16
+ end
17
+ else
18
+ url = oauth_client.web_server.authorize_url(
19
+ :scope => 'email,offline_access',
20
+ :redirect_uri => callback_url
21
+ )
22
+ throw(:halt, [ 302, {'Location' => url}, [ ]])
23
+ end
24
+ end
25
+
26
+ private
27
+ def oauth_client
28
+ OAuth2::Client.new(env['warden'].config[:github_client_id],
29
+ env['warden'].config[:github_secret],
30
+ :site => 'https://github.com',
31
+ :authorize_path => '/login/oauth/authorize',
32
+ :access_token_path => '/login/oauth/access_token')
33
+ end
34
+
35
+ def callback_url
36
+ absolute_url(request, env['warden'].config[:github_callback_url])
37
+ end
38
+
39
+ def absolute_url(request, suffix = nil)
40
+ port_part = case request.scheme
41
+ when "http"
42
+ request.port == 80 ? "" : ":#{request.port}"
43
+ when "https"
44
+ request.port == 443 ? "" : ":#{request.port}"
45
+ end
46
+ "#{request.scheme}://#{request.host}#{port_part}#{suffix}"
47
+ end
48
+ end
@@ -0,0 +1,17 @@
1
+ module Warden
2
+ module Github
3
+ module Oauth
4
+ class User < Struct.new(:attribs, :token)
5
+ extend Forwardable
6
+
7
+ def name
8
+ attribs['name']
9
+ end
10
+
11
+ def email
12
+ attribs['email']
13
+ end
14
+ end
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,5 @@
1
+ module Warden
2
+ module Github
3
+ VERSION = "0.0.1"
4
+ end
5
+ end
metadata ADDED
@@ -0,0 +1,119 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: warden-github
3
+ version: !ruby/object:Gem::Version
4
+ hash: 29
5
+ prerelease: false
6
+ segments:
7
+ - 0
8
+ - 0
9
+ - 1
10
+ version: 0.0.1
11
+ platform: ruby
12
+ authors:
13
+ - Corey Donohoe
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2010-06-01 00:00:00 -07:00
19
+ default_executable:
20
+ dependencies:
21
+ - !ruby/object:Gem::Dependency
22
+ prerelease: false
23
+ version_requirements: &id001 !ruby/object:Gem::Requirement
24
+ none: false
25
+ requirements:
26
+ - - ~>
27
+ - !ruby/object:Gem::Version
28
+ hash: 31
29
+ segments:
30
+ - 0
31
+ - 10
32
+ version: "0.10"
33
+ requirement: *id001
34
+ type: :runtime
35
+ name: warden
36
+ - !ruby/object:Gem::Dependency
37
+ prerelease: false
38
+ version_requirements: &id002 !ruby/object:Gem::Requirement
39
+ none: false
40
+ requirements:
41
+ - - ~>
42
+ - !ruby/object:Gem::Version
43
+ hash: 15
44
+ segments:
45
+ - 0
46
+ - 0
47
+ - 8
48
+ version: 0.0.8
49
+ requirement: *id002
50
+ type: :runtime
51
+ name: oauth2
52
+ - !ruby/object:Gem::Dependency
53
+ prerelease: false
54
+ version_requirements: &id003 !ruby/object:Gem::Requirement
55
+ none: false
56
+ requirements:
57
+ - - ~>
58
+ - !ruby/object:Gem::Version
59
+ hash: 1
60
+ segments:
61
+ - 1
62
+ - 4
63
+ - 3
64
+ version: 1.4.3
65
+ requirement: *id003
66
+ type: :runtime
67
+ name: json
68
+ description: A warden extension that integrates with github oauth
69
+ email: atmos@atmos.org
70
+ executables: []
71
+
72
+ extensions: []
73
+
74
+ extra_rdoc_files:
75
+ - LICENSE
76
+ files:
77
+ - LICENSE
78
+ - README.md
79
+ - Rakefile
80
+ - lib/warden-github/strategy.rb
81
+ - lib/warden-github/user.rb
82
+ - lib/warden-github/version.rb
83
+ - lib/warden-github.rb
84
+ has_rdoc: true
85
+ homepage: http://github.com/atmos/warden-github
86
+ licenses: []
87
+
88
+ post_install_message:
89
+ rdoc_options: []
90
+
91
+ require_paths:
92
+ - lib
93
+ required_ruby_version: !ruby/object:Gem::Requirement
94
+ none: false
95
+ requirements:
96
+ - - ">="
97
+ - !ruby/object:Gem::Version
98
+ hash: 3
99
+ segments:
100
+ - 0
101
+ version: "0"
102
+ required_rubygems_version: !ruby/object:Gem::Requirement
103
+ none: false
104
+ requirements:
105
+ - - ">="
106
+ - !ruby/object:Gem::Version
107
+ hash: 3
108
+ segments:
109
+ - 0
110
+ version: "0"
111
+ requirements: []
112
+
113
+ rubyforge_project:
114
+ rubygems_version: 1.3.7
115
+ signing_key:
116
+ specification_version: 3
117
+ summary: A warden extension that integrates with github oauth
118
+ test_files: []
119
+