lib/sinatra/auth/github.rb in sinatra_auth_github-0.3.1 vs lib/sinatra/auth/github.rb in sinatra_auth_github-0.4.0

- old
+ new

@@ -4,11 +4,11 @@ require 'rest_client' 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 class AccessDenied < Sinatra::Base enable :raise_errors @@ -58,21 +58,30 @@ # Supports a variety of methods, name, full_name, email, etc 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 # # Returns a rest client response object # # Examples # 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 # # path - the path on api.github.com to hit @@ -165,9 +174,10 @@ manager.failure_app = app.github_options[:failure_app] || BadAuthentication 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 app.helpers Helpers