forked from atmos/warden-github
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
break out the oauth2 stuff into a class so i can use it in the sinatr…
…a gem too
- Loading branch information
Showing
7 changed files
with
92 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
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 | ||
end | ||
|
||
def client | ||
@client ||= OAuth2::Client.new(@client_id, @secret, | ||
:site => 'https://github.com', | ||
:authorize_path => '/login/oauth/authorize', | ||
:access_token_path => '/login/oauth/access_token') | ||
end | ||
|
||
def access_token_for(code) | ||
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 | ||
) | ||
end | ||
|
||
def web_server | ||
client.web_server | ||
end | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
require File.dirname(__FILE__) + '/spec_helper' | ||
|
||
describe "Warden::Github::Oauth::Proxy" do | ||
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') | ||
end | ||
|
||
it "returns an authorize url" do | ||
uri = Addressable::URI.parse(@proxy.authorize_url) | ||
|
||
uri.scheme.should eql('https') | ||
uri.host.should eql('github.com') | ||
|
||
params = uri.query_values | ||
params['type'].should eql('web_server') | ||
params['scope'].should eql('email,offline_access') | ||
params['client_id'].should match(/\w{20}/) | ||
params['redirect_uri'].should eql('http://example.org/auth/github/callback') | ||
end | ||
|
||
it "has a client object" do | ||
@proxy.client.should_not be_nil | ||
end | ||
|
||
it "returns access tokens" do | ||
pending "this hits the network" do | ||
lambda { @proxy.access_token_for(/\w{20}/.gen) }.should_not raise_error | ||
end | ||
end | ||
end |