Sha256: 030ca9705ac2e6b17e5d44cd3ca3325f26ec4090001cb5e84a5b03a0f18f9dc7

Contents?: true

Size: 1.23 KB

Versions: 22

Compression:

Stored size: 1.23 KB

Contents

# frozen_string_literal: true

module Doorkeeper
  module OAuth
    class CodeResponse < BaseResponse
      include OAuth::Helpers

      attr_reader :pre_auth, :auth, :response_on_fragment

      def initialize(pre_auth, auth, options = {})
        @pre_auth = pre_auth
        @auth = auth
        @response_on_fragment = options[:response_on_fragment]
      end

      def redirectable?
        true
      end

      def issued_token
        auth.token
      end

      def body
        if auth.try(:access_token?)
          {
            access_token: auth.token.plaintext_token,
            token_type: auth.token.token_type,
            expires_in: auth.token.expires_in_seconds,
            state: pre_auth.state,
          }
        elsif auth.try(:access_grant?)
          {
            code: auth.token.plaintext_token,
            state: pre_auth.state,
          }
        end
      end

      def redirect_uri
        if URIChecker.oob_uri?(pre_auth.redirect_uri)
          auth.oob_redirect
        elsif response_on_fragment
          Authorization::URIBuilder.uri_with_fragment(pre_auth.redirect_uri, body)
        else
          Authorization::URIBuilder.uri_with_query(pre_auth.redirect_uri, body)
        end
      end
    end
  end
end

Version data entries

22 entries across 22 versions & 1 rubygems

Version Path
doorkeeper-5.8.1 lib/doorkeeper/oauth/code_response.rb
doorkeeper-5.8.0 lib/doorkeeper/oauth/code_response.rb
doorkeeper-5.7.1 lib/doorkeeper/oauth/code_response.rb
doorkeeper-5.7.0 lib/doorkeeper/oauth/code_response.rb
doorkeeper-5.6.9 lib/doorkeeper/oauth/code_response.rb
doorkeeper-5.6.8 lib/doorkeeper/oauth/code_response.rb
doorkeeper-5.6.7 lib/doorkeeper/oauth/code_response.rb
doorkeeper-5.6.6 lib/doorkeeper/oauth/code_response.rb
doorkeeper-5.6.5 lib/doorkeeper/oauth/code_response.rb
doorkeeper-5.6.4 lib/doorkeeper/oauth/code_response.rb
doorkeeper-5.6.3 lib/doorkeeper/oauth/code_response.rb
doorkeeper-5.6.2 lib/doorkeeper/oauth/code_response.rb
doorkeeper-5.6.1 lib/doorkeeper/oauth/code_response.rb
doorkeeper-5.6.0 lib/doorkeeper/oauth/code_response.rb
doorkeeper-5.6.0.rc2 lib/doorkeeper/oauth/code_response.rb
doorkeeper-5.6.0.rc1 lib/doorkeeper/oauth/code_response.rb
doorkeeper-5.5.4 lib/doorkeeper/oauth/code_response.rb
doorkeeper-5.5.3 lib/doorkeeper/oauth/code_response.rb
doorkeeper-5.5.2 lib/doorkeeper/oauth/code_response.rb
doorkeeper-5.5.1 lib/doorkeeper/oauth/code_response.rb