File: code_response.rb

package info (click to toggle)
ruby-doorkeeper 5.8.2-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 992 kB
  • sloc: ruby: 4,644; makefile: 4
file content (51 lines) | stat: -rw-r--r-- 1,256 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# 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