Sha256: 47de7c92c58d2bfacdbcb1e1a1a135f35f3774e994142cd1c9696a68b7f52919

Contents?: true

Size: 1.81 KB

Versions: 18

Compression:

Stored size: 1.81 KB

Contents

require 'doorkeeper/openid_connect/rails/routes/mapping'
require 'doorkeeper/openid_connect/rails/routes/mapper'

module Doorkeeper
  module OpenidConnect
    module Rails
      class Routes
        module Helper
          def use_doorkeeper_openid_connect(options = {}, &block)
            Doorkeeper::OpenidConnect::Rails::Routes.new(self, &block).generate_routes!(options)
          end
        end

        def self.install!
          ActionDispatch::Routing::Mapper.send :include, Doorkeeper::OpenidConnect::Rails::Routes::Helper
        end

        attr_accessor :routes

        def initialize(routes, &block)
          @routes = routes
          @block = block
        end

        def generate_routes!(options)
          @mapping = Mapper.new.map(&@block)
          routes.scope options[:scope] || 'oauth', as: 'oauth' do
            map_route(:userinfo, :userinfo_routes)
            map_route(:discovery, :discovery_routes)
          end

          routes.scope as: 'oauth' do
            map_route(:discovery, :discovery_well_known_routes)
          end
        end

        private

        def map_route(name, method)
          return if @mapping.skipped?(name)

          mapping = @mapping[name]

          routes.scope controller: mapping[:controllers], as: mapping[:as] do
            send method
          end
        end

        def userinfo_routes
          routes.get :show, path: 'userinfo', as: ''
          routes.post :show, path: 'userinfo', as: nil
        end

        def discovery_routes
          routes.scope path: 'discovery' do
            routes.get :keys
          end
        end

        def discovery_well_known_routes
          routes.scope path: '.well-known' do
            routes.get :provider, path: 'openid-configuration'
            routes.get :webfinger
          end
        end
      end
    end
  end
end

Version data entries

18 entries across 18 versions & 1 rubygems

Version Path
doorkeeper-openid_connect-1.7.1 lib/doorkeeper/openid_connect/rails/routes.rb
doorkeeper-openid_connect-1.7.0 lib/doorkeeper/openid_connect/rails/routes.rb
doorkeeper-openid_connect-1.6.3 lib/doorkeeper/openid_connect/rails/routes.rb
doorkeeper-openid_connect-1.6.2 lib/doorkeeper/openid_connect/rails/routes.rb
doorkeeper-openid_connect-1.6.1 lib/doorkeeper/openid_connect/rails/routes.rb
doorkeeper-openid_connect-1.6.0 lib/doorkeeper/openid_connect/rails/routes.rb
doorkeeper-openid_connect-1.5.5 lib/doorkeeper/openid_connect/rails/routes.rb
doorkeeper-openid_connect-1.5.4 lib/doorkeeper/openid_connect/rails/routes.rb
doorkeeper-openid_connect-1.5.3 lib/doorkeeper/openid_connect/rails/routes.rb
doorkeeper-openid_connect-1.5.2 lib/doorkeeper/openid_connect/rails/routes.rb
doorkeeper-openid_connect-1.5.1 lib/doorkeeper/openid_connect/rails/routes.rb
doorkeeper-openid_connect-1.5.0 lib/doorkeeper/openid_connect/rails/routes.rb
doorkeeper-openid_connect-1.4.0 lib/doorkeeper/openid_connect/rails/routes.rb
doorkeeper-openid_connect-1.3.0 lib/doorkeeper/openid_connect/rails/routes.rb
doorkeeper-openid_connect-1.2.0 lib/doorkeeper/openid_connect/rails/routes.rb
doorkeeper-openid_connect-1.1.2 lib/doorkeeper/openid_connect/rails/routes.rb
doorkeeper-openid_connect-1.1.1 lib/doorkeeper/openid_connect/rails/routes.rb
doorkeeper-openid_connect-1.1.0 lib/doorkeeper/openid_connect/rails/routes.rb