Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Fix custom site for oauth #100

Merged
merged 2 commits into from

3 participants

@5long

Hi, I've been using this Github client library and found it easy to work with. However, I've encountered this problem with authorization. The problem is demostrated by commit e201c7e and fixed in the later commit.

I admit that I'm breaking the current design a little bit. But I guess the Github::Client#client method should be private anyway and I believe my approach actually made it harder to misuse.

Feel free to tell me what more to do to get this patch merged so that I can remove some workaround from my app :)

@coveralls

Coverage decreased (-0.05%) when pulling 4b27063 on 5long:fix-custom-site-for-oauth into 76cd473 on peter-murach:master.

View Details

@peter-murach peter-murach merged commit 018aaa9 into peter-murach:master
@peter-murach
Owner

Hi, this is a quality patch and I was more than happy to merge it in, even more so as this is the 100th issue:) I agree with your observation about making the client private. Thanks a lot, I've released v0.9.5 that includes your patch as well as some minor changes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
This page is out of date. Refresh to see the latest.
View
1  lib/github_api/api.rb
@@ -41,7 +41,6 @@ class API
#
def initialize(options={}, &block)
setup(options)
- client(options) if client_id? && client_secret?
yield_or_eval(&block) if block_given?
end
View
4 lib/github_api/authorization.rb
@@ -6,10 +6,10 @@ module Authorization
attr_accessor :scopes
# Setup OAuth2 instance
- def client(options={})
+ def client
@client ||= ::OAuth2::Client.new(client_id, client_secret,
{
- :site => options.fetch(:site) { Github.site },
+ :site => current_options.fetch(:site) { Github.site },
:authorize_url => 'login/oauth/authorize',
:token_url => 'login/oauth/access_token',
:ssl => { :verify => false }
View
9 spec/github/authorization_spec.rb
@@ -6,7 +6,8 @@
let(:client_id) { '234jl23j4l23j4l' }
let(:client_secret) { 'asasd79sdf9a7asfd7sfd97s' }
let(:code) { 'c9798sdf97df98ds'}
- let(:options) { {} }
+ let(:site) { 'http://github-ent.example.com/' }
+ let(:options) { {:site => site} }
subject(:github) { Github.new options }
@@ -22,15 +23,15 @@
end
it "should assign site from the options hash" do
- github.client.site.should == 'https://github.com'
+ github.client.site.should == site
end
it "should assign 'authorize_url" do
- github.client.authorize_url.should == 'https://github.com/login/oauth/authorize'
+ github.client.authorize_url.should == "#{site}login/oauth/authorize"
end
it "should assign 'token_url" do
- github.client.token_url.should == 'https://github.com/login/oauth/access_token'
+ github.client.token_url.should == "#{site}login/oauth/access_token"
end
end
Something went wrong with that request. Please try again.