Sha256: 5321cbd42fabc69bd44de132d9988fdd1973db6b03f0693aa2e69852a0727d88

Contents?: true

Size: 919 Bytes

Versions: 5

Compression:

Stored size: 919 Bytes

Contents

module Roqua
  module CoreApi
    module Sessions
      class OAuthSession < AuthSession
        attr_reader :access_token

        def initialize(access_token:, **additional_arguments)
          @access_token = access_token
          super additional_arguments
        end

        def logout_url(return_to:)
          "#{core_site}/session/destroy?token=#{access_token}&return_to=#{CGI.escape return_to}"
        end

        # ping the server to check if session is still valid.
        # Will throw NoSession as usual if not.
        def ping
          get "/ping"
        end

        private

        def access_denied(response)
          if response['no_session']
            fail NoSession
          else
            fail Unauthorized
          end
        end

        def headers(_request_method, _path, _params)
          {"Authorization" => "Bearer #{access_token}"}
        end
      end
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
roqua-core-api-0.3.1 lib/roqua/core_api/sessions/oauth_session.rb
roqua-core-api-0.3.0 lib/roqua/core_api/sessions/oauth_session.rb
roqua-core-api-0.2.4 lib/roqua/core_api/sessions/oauth_session.rb
roqua-core-api-0.2.3 lib/roqua/core_api/sessions/oauth_session.rb
roqua-core-api-0.2.2 lib/roqua/core_api/sessions/oauth_session.rb