Sha256: 40608848a6ff7a1effef0d6fc0ce453c3be578060e211568e8f6c2b9b5949016

Contents?: true

Size: 1.23 KB

Versions: 101

Compression:

Stored size: 1.23 KB

Contents

module Bearcat
  class Client < Footrest::Client
    module OAuth2

      def auth_redirect_url(client_id, redirect_uri, opts = {})
        opts[:response_type] ||= 'code'

        fullpath('login/oauth2/auth')
        uri = URI.parse(fullpath('login/oauth2/auth'))
        query = [
          ['client_id', client_id],
          ['redirect_uri', redirect_uri],
          ['response_type', opts[:response_type]]
        ]
        query << ['state', opts[:state]] if opts[:state]
        query << ['scopes', opts[:scope]] if opts[:scope]
        uri.query = URI.encode_www_form(query)
        uri.to_s
      end

      def retrieve_token(client_id, redirect_url, client_secret, code, grant_type = 'authorization_code')
        token_params = {
          client_id: client_id,
          redirect_url: redirect_url,
          client_secret: client_secret,
          grant_type: grant_type
        }
        if grant_type == 'authorization_code'
          token_params[:code] = code
        elsif grant_type == 'refresh_token'
          token_params[:refresh_token] = code
        end
        body = post('/login/oauth2/token', token_params)
        config[:token] = body['access_token']
        set_connection(config)
        body
      end

    end
  end
end

Version data entries

101 entries across 101 versions & 1 rubygems

Version Path
bearcat-1.5.13 lib/bearcat/client/o_auth2.rb
bearcat-1.5.12 lib/bearcat/client/o_auth2.rb
bearcat-1.5.11 lib/bearcat/client/o_auth2.rb
bearcat-1.5.10 lib/bearcat/client/o_auth2.rb
bearcat-1.5.9 lib/bearcat/client/o_auth2.rb
bearcat-1.5.8 lib/bearcat/client/o_auth2.rb
bearcat-1.5.7 lib/bearcat/client/o_auth2.rb
bearcat-1.5.6 lib/bearcat/client/o_auth2.rb
bearcat-1.5.5 lib/bearcat/client/o_auth2.rb
bearcat-1.5.4 lib/bearcat/client/o_auth2.rb
bearcat-1.5.3 lib/bearcat/client/o_auth2.rb
bearcat-1.5.2 lib/bearcat/client/o_auth2.rb
bearcat-1.5.0 lib/bearcat/client/o_auth2.rb
bearcat-1.5.0.beta4 lib/bearcat/client/o_auth2.rb
bearcat-1.5.0.beta3 lib/bearcat/client/o_auth2.rb
bearcat-1.5.0.beta2 lib/bearcat/client/o_auth2.rb
bearcat-1.5.0.beta1 lib/bearcat/client/o_auth2.rb
bearcat-1.4.13 lib/bearcat/client/o_auth2.rb
bearcat-1.4.12 lib/bearcat/client/o_auth2.rb
bearcat-1.4.11 lib/bearcat/client/o_auth2.rb