Sha256: 08e4444e1456559e15a210c0b11d9fec0f686bdef47bdd5f738ce87df58b35df

Contents?: true

Size: 987 Bytes

Versions: 2

Compression:

Stored size: 987 Bytes

Contents

module Flattr
  module OAuth2

    def authorize_url(opts = {})

      default_options = {
        :client_id => client_id,
        :client_secret => client_secret,
        :response_type => "code"
      }

      opts = default_options.merge(opts)

      if !opts[:scope].nil?
        if opts[:scope].is_a?(Array)
          opts[:scope] = opts[:scope].join(",")
        end
      end

      query_string = %w(response_type client_id redirect_uri scope state).collect do |key|
        "#{key.to_s}=#{opts[key.to_sym]}" if opts[key.to_sym]
      end.compact.join("&")

      "#{authorize_endpoint}/?#{query_string}"
    end

    def get_access_token(code)
      response = post(token_endpoint, {
        :code => code,
        :grant_type => 'authorization_code'
      },{
        :headers => {
          :authorization => "Basic #{base64_encode("#{client_id}:#{client_secret}")}"
        }}
      )
      self.access_token = response['access_token']
      access_token
    end

  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
flattr-0.2.3 lib/flattr/oauth2.rb
flattr-0.2.2 lib/flattr/oauth2.rb