Sha256: d8b8b2b5c2eb0240afc1e23914e6b34fed9dd513aa7a5bf895aa1efbb0017216

Contents?: true

Size: 1.28 KB

Versions: 10

Compression:

Stored size: 1.28 KB

Contents

module Warden
  module Github
    module Oauth
      class Proxy
        attr_accessor :client_id, :secret, :scopes, :oauth_domain, :callback_url
        def initialize(client_id, secret, scopes, oauth_domain, callback_url)
          @client_id, @secret, @scopes, @oauth_domain, @callback_url = client_id, secret, scopes, oauth_domain, callback_url
        end

        def ssl_options
          ca_file = "/usr/lib/ssl/certs/ca-certificates.crt"
          if File.exists?(ca_file)
            { :ca_file => ca_file }
          else
            { :ca_file => ''}
          end
        end

        def client
          @client ||= OAuth2::Client.new(@client_id, @secret,
                                         :ssl           => ssl_options,
                                         :site          => oauth_domain,
                                         :token_url     => '/login/oauth/access_token',
                                         :authorize_url => '/login/oauth/authorize')
        end

        def api_for(code)
          client.auth_code.get_token(code, :redirect_uri => callback_url)
        end

        def authorize_url
          client.auth_code.authorize_url(
            :scope        => scopes,
            :redirect_uri => callback_url
          )
        end
      end
    end
  end
end

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
warden-github-0.7.0 lib/warden-github/proxy.rb
warden-github-0.6.1 lib/warden-github/proxy.rb
warden-github-0.6.0 lib/warden-github/proxy.rb
warden-github-0.5.1 lib/warden-github/proxy.rb
warden-github-0.5.0 lib/warden-github/proxy.rb
warden-github-0.4.4 lib/warden-github/proxy.rb
warden-github-0.4.3 lib/warden-github/proxy.rb
warden-github-0.4.2 lib/warden-github/proxy.rb
warden-github-0.4.1 lib/warden-github/proxy.rb
warden-github-0.4.0 lib/warden-github/proxy.rb