Sha256: cf4e8ebcbb6e0a1ea54b6b31c284f7e4a8272cd2f8257700dd8edb364470a1b2

Contents?: true

Size: 1.22 KB

Versions: 9

Compression:

Stored size: 1.22 KB

Contents

module OAuth
  # The RequestToken is used for the initial Request.
  # This is normally created by the Consumer object.
  class RequestToken < ConsumerToken

    # Generate an authorization URL for user authorization
    def authorize_url(params = nil)
      return nil if self.token.nil?

      params = (params || {}).merge(:oauth_token => self.token)
      build_authorize_url(consumer.authorize_url, params)
    end

    def callback_confirmed?
      params[:oauth_callback_confirmed] == "true"
    end

    # exchange for AccessToken on server
    def get_access_token(options = {}, *arguments)
      response = consumer.token_request(consumer.http_method, (consumer.access_token_url? ? consumer.access_token_url : consumer.access_token_path), self, options, *arguments)
      OAuth::AccessToken.from_hash(consumer, response)
    end

  protected

    # construct an authorization url
    def build_authorize_url(base_url, params)
      uri = URI.parse(base_url.to_s)
      queries = {}
      queries = Hash[URI.decode_www_form(uri.query)] if uri.query
      # TODO doesn't handle array values correctly
      queries.merge!(params) if params
      uri.query = URI.encode_www_form(queries) if !queries.empty?
      uri.to_s
    end
  end
end

Version data entries

9 entries across 7 versions & 2 rubygems

Version Path
tdiary-5.0.8 vendor/bundle/gems/oauth-0.5.4/lib/oauth/tokens/request_token.rb
oauth-0.5.4 lib/oauth/tokens/request_token.rb
tdiary-5.0.5 vendor/bundle/gems/tdiary-5.0.4/vendor/bundle/gems/oauth-0.5.1/lib/oauth/tokens/request_token.rb
tdiary-5.0.5 vendor/bundle/gems/oauth-0.5.1/lib/oauth/tokens/request_token.rb
tdiary-5.0.5 vendor/bundle/gems/oauth-0.5.3/lib/oauth/tokens/request_token.rb
oauth-0.5.3 lib/oauth/tokens/request_token.rb
oauth-0.5.2 lib/oauth/tokens/request_token.rb
tdiary-5.0.4 vendor/bundle/gems/oauth-0.5.1/lib/oauth/tokens/request_token.rb
oauth-0.5.1 lib/oauth/tokens/request_token.rb