Class: Doorkeeper::OAuth::MetadataResponse

Inherits:
BaseResponse show all
Defined in:
lib/doorkeeper/oauth/metadata_response.rb

Overview

OAuth 2.0 Authorization Server Metadata response as described in RFC 8414 (https://www.rfc-editor.org/rfc/rfc8414).

Instance Method Summary collapse

Methods inherited from BaseResponse

#description, #redirect_uri, #redirectable?

Constructor Details

#initialize(base_url, url_builder) ⇒ MetadataResponse

Returns a new instance of MetadataResponse.



8
9
10
11
12
# File 'lib/doorkeeper/oauth/metadata_response.rb', line 8

def initialize(base_url, url_builder)
  super()
  @base_url = base_url
  @url_builder = url_builder
end

Instance Method Details

#bodyObject



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
# File 'lib/doorkeeper/oauth/metadata_response.rb', line 14

def body
  @body ||= begin
    data = {
      # presence: a blank issuer (e.g. an unset env var) must fall back
      # to base_url, matching the issuer.present? condition below so the
      # two fields cannot disagree.
      issuer: issuer.presence || @base_url,
      # Only advertise endpoints whose controllers are installed. A
      # controller disabled through skip_controllers has no routes mapping,
      # so endpoint_for resolves it to nil and it is dropped below.
      authorization_endpoint: authorization_endpoint,
      token_endpoint: token_endpoint,
      revocation_endpoint: revocation_endpoint,
      introspection_endpoint: (introspection_endpoint if introspection_enabled?),
      scopes_supported: scopes_supported,
      response_types_supported: response_types_supported,
      response_modes_supported: response_modes_supported,
      grant_types_supported: grant_types_supported,
      token_endpoint_auth_methods_supported: token_endpoint_auth_methods_supported,
      code_challenge_methods_supported: code_challenge_methods_supported,
      # RFC 9207: true only when an issuer is configured, matching the
      # condition under which the iss parameter is emitted. false survives
      # the compaction below, so it is advertised explicitly.
      authorization_response_iss_parameter_supported: config.issuer.present?,
      # RFC 8707: advertise resource indicator support when configured.
      resource_indicators_supported: resource_indicators_supported?,
    }
    data.compact!

    # userinfo_endpoint is intentionally advertised as null for backwards
    # compatibility; it is meant to be populated through custom_metadata
    # (e.g. by an OIDC extension), so it must survive the compaction above.
    data[:userinfo_endpoint] = userinfo_endpoint

    data.merge()
  end
end

#headersObject



56
57
58
59
60
61
# File 'lib/doorkeeper/oauth/metadata_response.rb', line 56

def headers
  {
    "Cache-Control" => "public",
    "Content-Type" => "application/json; charset=utf-8",
  }
end

#statusObject



52
53
54
# File 'lib/doorkeeper/oauth/metadata_response.rb', line 52

def status
  :ok
end