Skip to content
This repository has been archived by the owner on Nov 10, 2017. It is now read-only.

Commit

Permalink
configurable oauth endpoints for local testing
Browse files Browse the repository at this point in the history
  • Loading branch information
atmos committed Mar 2, 2012
1 parent 1f3620b commit 39ff84a
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 4 deletions.
1 change: 1 addition & 0 deletions README.md
Expand Up @@ -56,3 +56,4 @@ Extension Options
* `:client_id` - The client id that GitHub provides * `:client_id` - The client id that GitHub provides
* `:failure_app` - A Sinatra::Base class that has a route for `/unauthenticated`, Useful for overriding the securocat default page. * `:failure_app` - A Sinatra::Base class that has a route for `/unauthenticated`, Useful for overriding the securocat default page.
* `:callback_url` - The path that GitHub posts back to, defaults to `/auth/github/callback`. * `:callback_url` - The path that GitHub posts back to, defaults to `/auth/github/callback`.
* `:oauth_domain` - The scheme and host that's GitHub's endpoint, defaults to `https://github.com`
14 changes: 12 additions & 2 deletions lib/sinatra/auth/github.rb
Expand Up @@ -6,7 +6,7 @@
module Sinatra module Sinatra
module Auth module Auth
module Github module Github
VERSION = "0.3.0" VERSION = "0.4.0"


# Simple way to serve an image early in the stack and not get blocked by # Simple way to serve an image early in the stack and not get blocked by
# application level before filters # application level before filters
Expand Down Expand Up @@ -60,6 +60,15 @@ def github_user
warden.user warden.user
end end


def github_api_uri
if ENV['GITHUB_OAUTH_API_DOMAIN']
ENV['GITHUB_OAUTH_API_DOMAIN']
else
uri = URI.parse(env['warden'].config[:github_oauth_domain])
"#{uri.scheme}://api.#{uri.host}"
end
end

# Send a V3 API GET request to path # Send a V3 API GET request to path
# #
# path - the path on api.github.com to hit # path - the path on api.github.com to hit
Expand All @@ -70,7 +79,7 @@ def github_user
# github_raw_request("/user") # github_raw_request("/user")
# # => RestClient::Response # # => RestClient::Response
def github_raw_request(path) def github_raw_request(path)
RestClient.get("https://api.github.com/#{path}", :params => { :access_token => github_user.token }, :accept => :json) RestClient.get("#{github_api_uri}/#{path}", :params => { :access_token => github_user.token }, :accept => :json)
end end


# Send a V3 API GET request to path and parse the response body # Send a V3 API GET request to path and parse the response body
Expand Down Expand Up @@ -167,6 +176,7 @@ def self.registered(app)
manager[:github_secret] = app.github_options[:secret] || ENV['GITHUB_CLIENT_SECRET'] manager[:github_secret] = app.github_options[:secret] || ENV['GITHUB_CLIENT_SECRET']
manager[:github_scopes] = app.github_options[:scopes] || '' manager[:github_scopes] = app.github_options[:scopes] || ''
manager[:github_client_id] = app.github_options[:client_id] || ENV['GITHUB_CLIENT_ID'] manager[:github_client_id] = app.github_options[:client_id] || ENV['GITHUB_CLIENT_ID']
manager[:github_oauth_domain] = app.github_options[:oauth_domain] || ENV['GITHUB_OAUTH_DOMAIN'] || 'https://github.com'
manager[:github_callback_url] = app.github_options[:callback_url] || '/auth/github/callback' manager[:github_callback_url] = app.github_options[:callback_url] || '/auth/github/callback'
end end


Expand Down
4 changes: 2 additions & 2 deletions sinatra_auth_github.gemspec
Expand Up @@ -3,7 +3,7 @@ $:.push File.expand_path("../lib", __FILE__)


Gem::Specification.new do |s| Gem::Specification.new do |s|
s.name = "sinatra_auth_github" s.name = "sinatra_auth_github"
s.version = "0.3.1" s.version = "0.4.0"
s.platform = Gem::Platform::RUBY s.platform = Gem::Platform::RUBY
s.authors = ["Corey Donohoe"] s.authors = ["Corey Donohoe"]
s.email = ["atmos@atmos.org"] s.email = ["atmos@atmos.org"]
Expand All @@ -16,7 +16,7 @@ Gem::Specification.new do |s|
s.add_dependency "sinatra", "~>1.0" s.add_dependency "sinatra", "~>1.0"
s.add_dependency "yajl-ruby", "~>1.1" s.add_dependency "yajl-ruby", "~>1.1"
s.add_dependency "rest-client", "~>1.6.1" s.add_dependency "rest-client", "~>1.6.1"
s.add_dependency "warden-github", "~>0.3.0" s.add_dependency "warden-github", "~>0.4.0"


s.add_development_dependency "rake" s.add_development_dependency "rake"
s.add_development_dependency "rspec", "~>1.3.0" s.add_development_dependency "rspec", "~>1.3.0"
Expand Down
1 change: 1 addition & 0 deletions spec/app.rb
@@ -1,4 +1,5 @@
require 'pp' require 'pp'
require 'ruby-debug'


module Example module Example
class App < Sinatra::Base class App < Sinatra::Base
Expand Down

0 comments on commit 39ff84a

Please sign in to comment.