Permalink
Browse files

start support oauth2 scopes on github

  • Loading branch information...
1 parent 3a7caa8 commit 7a341ab792ba82f9c101fabe8f2de0da056c6619 @atmos atmos committed Jun 18, 2010
Showing with 13 additions and 10 deletions.
  1. +6 −5 lib/warden-github/proxy.rb
  2. +1 −0 lib/warden-github/strategy.rb
  3. +3 −2 spec/app.rb
  4. +1 −1 spec/oauth_spec.rb
  5. +2 −2 spec/proxy_spec.rb
View
@@ -2,8 +2,9 @@ module Warden
module Github
module Oauth
class Proxy
- def initialize(client_id, secret, callback_url)
- @client_id, @secret, @callback_url = client_id, secret, callback_url
+ attr_accessor :client_id, :secret, :scopes, :callback_url
+ def initialize(client_id, secret, scopes, callback_url)
+ @client_id, @secret, @scopes, @callback_url = client_id, secret, scopes, callback_url
end
def client
@@ -14,13 +15,13 @@ def client
end
def access_token_for(code)
- web_server.get_access_token(code, :redirect_uri => @callback_url)
+ web_server.get_access_token(code, :redirect_uri => callback_url)
end
def authorize_url
web_server.authorize_url(
- :scope => 'email,offline_access',
- :redirect_uri => @callback_url
+ :scope => scopes,
+ :redirect_uri => callback_url
)
end
@@ -36,6 +36,7 @@ def access_token_for(code)
def oauth_proxy
@oauth_proxy ||= Warden::Github::Oauth::Proxy.new(env['warden'].config[:github_client_id],
env['warden'].config[:github_secret],
+ env['warden'].config[:github_scopes],
callback_url)
end
View
@@ -8,9 +8,10 @@ class App < Sinatra::Base
manager.default_strategies :github
manager.failure_app = BadAuthentication
- manager[:github_secret] = ENV['GH_SECRET'] || 'ed8ff0c54067aefb808dab1ca265865405d08d6f'
- manager[:github_client_id] = ENV['GH_CLIENT_ID'] || 'ee9aa24b64d82c21535a'
manager[:github_callback_url] = '/auth/github/callback'
+ manager[:github_client_id] = ENV['GH_CLIENT_ID'] || 'ee9aa24b64d82c21535a'
+ manager[:github_secret] = ENV['GH_SECRET'] || 'ed8ff0c54067aefb808dab1ca265865405d08d6f'
+ manager[:github_scopes] = 'email,offline_access,repo,gist'
end
helpers do
View
@@ -11,7 +11,7 @@
params = uri.query_values
params['type'].should eql('web_server')
- params['scope'].should eql('email,offline_access')
+ params['scope'].should eql('email,offline_access,repo,gist')
params['client_id'].should match(/\w{20}/)
params['redirect_uri'].should eql('http://example.org/auth/github/callback')
end
View
@@ -4,7 +4,7 @@
before(:all) do
sha = Digest::SHA1.hexdigest(Time.now.to_s)
@proxy = Warden::Github::Oauth::Proxy.new(sha[0..19], sha[0..39],
- 'http://example.org/auth/github/callback')
+ 'email,offline_access,repo', 'http://example.org/auth/github/callback')
end
it "returns an authorize url" do
@@ -15,7 +15,7 @@
params = uri.query_values
params['type'].should eql('web_server')
- params['scope'].should eql('email,offline_access')
+ params['scope'].should eql('email,offline_access,repo')
params['client_id'].should match(/\w{20}/)
params['redirect_uri'].should eql('http://example.org/auth/github/callback')
end

0 comments on commit 7a341ab

Please sign in to comment.