Sha256: 6e35ebdc280eecc5fb443b19f4a9022eaf4cf0394ba20368e798773e185fa14f

Contents?: true

Size: 1.17 KB

Versions: 9

Compression:

Stored size: 1.17 KB

Contents

module Mautic
  module Connections
    class Oauth2 < Mautic::Connection

      def client
        @client ||= OAuth2::Client.new(client_id, secret, {
          site: url,
          authorize_url: 'oauth/v2/authorize',
          token_url: 'oauth/v2/token',
          raise_errors: false
        })
      end

      def authorize
        client.auth_code.authorize_url(redirect_uri: callback_url)
      end

      def get_code(code)
        client.auth_code.get_token(code, redirect_uri: callback_url)
      end

      def connection
        @connection ||= OAuth2::AccessToken.new(client, token, { refresh_token: refresh_token })
      end

      def refresh!
        @connection = connection.refresh!
        update(token: @connection.token, refresh_token: @connection.refresh_token)
        @connection
      end

      def request(type, path, params = {})
        @last_request = [type, path, params]
        response = connection.request(type, path, params)
        parse_response(response)
      end

      private

      def callback_url
        uri = super
        uri.path = Mautic::Engine.routes.url_helpers.oauth2_connection_path(self)
        uri.to_s
      end

    end
  end
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
mautic-2.3.8 app/models/mautic/connections/oauth2.rb
mautic-2.3.7 app/models/mautic/connections/oauth2.rb
mautic-2.3.6 app/models/mautic/connections/oauth2.rb
mautic-2.3.5 app/models/mautic/connections/oauth2.rb
mautic-2.3.4 app/models/mautic/connections/oauth2.rb
mautic-2.3.3 app/models/mautic/connections/oauth2.rb
mautic-2.3.1 app/models/mautic/connections/oauth2.rb
mautic-2.2.2 app/models/mautic/connections/oauth2.rb
mautic-2.1.1 app/models/mautic/connections/oauth2.rb