Permalink
Browse files

configurable oauth endpoints for local testing

  • Loading branch information...
1 parent 1f3620b commit 39ff84ae26832d41c9b1fba34284296c140cfa52 @atmos committed Mar 2, 2012
Showing with 16 additions and 4 deletions.
  1. +1 −0 README.md
  2. +12 −2 lib/sinatra/auth/github.rb
  3. +2 −2 sinatra_auth_github.gemspec
  4. +1 −0 spec/app.rb
View
@@ -56,3 +56,4 @@ Extension Options
* `: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.
* `: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`
View
@@ -6,7 +6,7 @@
module Sinatra
module Auth
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
# application level before filters
@@ -60,6 +60,15 @@ def github_user
warden.user
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
#
# path - the path on api.github.com to hit
@@ -70,7 +79,7 @@ def github_user
# github_raw_request("/user")
# # => RestClient::Response
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
# Send a V3 API GET request to path and parse the response body
@@ -167,6 +176,7 @@ def self.registered(app)
manager[:github_secret] = app.github_options[:secret] || ENV['GITHUB_CLIENT_SECRET']
manager[:github_scopes] = app.github_options[:scopes] || ''
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'
end
@@ -3,7 +3,7 @@ $:.push File.expand_path("../lib", __FILE__)
Gem::Specification.new do |s|
s.name = "sinatra_auth_github"
- s.version = "0.3.1"
+ s.version = "0.4.0"
s.platform = Gem::Platform::RUBY
s.authors = ["Corey Donohoe"]
s.email = ["atmos@atmos.org"]
@@ -16,7 +16,7 @@ Gem::Specification.new do |s|
s.add_dependency "sinatra", "~>1.0"
s.add_dependency "yajl-ruby", "~>1.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 "rspec", "~>1.3.0"
View
@@ -1,4 +1,5 @@
require 'pp'
+require 'ruby-debug'
module Example
class App < Sinatra::Base

0 comments on commit 39ff84a

Please sign in to comment.