Sha256: ceb6183237d0f61bc415fa8f8fae3ccdcc879783b44d6edda28f6bfea07dc957

Contents?: true

Size: 1.59 KB

Versions: 3

Compression:

Stored size: 1.59 KB

Contents

# frozen_string_literal: true

require 'yori/schema/v3/oauth_flow'

module Yori
  module Schema
    module V3
      # OAuthFlows: Allows configuration of the supported OAuth Flows.
      class OAuthFlows < Yori::SchemaBase
        # @!method implicit
        #   Configuration for the OAuth Implicit flow
        field_block :implicit, Yori::Schema::V3::OAuthFlow
        # @!method password
        #   Configuration for the OAuth Resource Owner Password flow
        field_block :password, Yori::Schema::V3::OAuthFlow
        # @!method clientCredentials
        #   Configuration for the OAuth Client Credentials flow.
        #   Previously called application in OpenAPI 2.0.
        field_block :clientCredentials, Yori::Schema::V3::OAuthFlow
        # @!method authorizationCode
        #   Configuration for the OAuth Authorization Code flow.
        #   Previously called accessCode in OpenAPI 2.0.
        field_block :authorizationCode, Yori::Schema::V3::OAuthFlow

        def validate!
          %w[implicit clientCredentials authorizationCode].each do |field|
            validate_flow!(field)
          end
        end

        def validate_flow!(flow)
          oauth_flow = self[flow]
          oauth_flow&.validate_require_fields!(*required_flow_fields(flow))
        end

        def required_flow_fields(flow)
          case flow
          when 'implicit'
            %w[authorizationUrl]
          when 'clientCredentials'
            %w[tokenUrl]
          when 'authorizationCode'
            %w[authorizationUrl tokenUrl]
          else
            []
          end
        end
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
yori-0.1.2 lib/yori/schema/v3/oauth_flows.rb
yori-0.1.1 lib/yori/schema/v3/oauth_flows.rb
yori-0.1.0 lib/yori/schema/v3/oauth_flows.rb