Sha256: ff7e003bdebb68beaa8e1cf56eb456108ade9aa4bdd86294578c94b34379947c

Contents?: true

Size: 1.17 KB

Versions: 1

Compression:

Stored size: 1.17 KB

Contents

require 'rack/oauth2'

require 'oauth2-auth-server/version'
require 'oauth2-auth-server/schema'
require 'oauth2-auth-server/routes'

module Oauth2
  module Auth
    module Server
      autoload :SecureToken, 'oauth2-auth-server/secure_token'
      autoload :Authentication, 'oauth2-auth-server/authentication'

      module Endpoints
        autoload :Authorize, 'oauth2-auth-server/endpoints/authorize'
        autoload :Token, 'oauth2-auth-server/endpoints/token'
      end

      module Models
        autoload :AccessToken, 'oauth2-auth-server/models/access_token'
        autoload :Client, 'oauth2-auth-server/models/client'
      end

      mattr_accessor :default_lifetime
      @@default_lifetime = nil

      def self.setup
        yield self
      end

      def self.use_middleware(type)
        token_type = case type
          when :bearer then Rack::OAuth2::Server::Resource::Bearer
          else raise("Token type '#{type}' is not supported")
        end
        Rails.application.config.middleware.use token_type, 'Rack::OAuth2 Protected Resources' do |req|
          AccessToken.valid.find_by_token(req.access_token) || req.invalid_token!
        end
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
oauth2-auth-server-0.0.1 lib/oauth2-auth-server.rb