Sha256: e65159e9091e6d30d9f9faadb97affc7300218cbb010e45b3bf0c5e16dc6df8c

Contents?: true

Size: 1.16 KB

Versions: 1

Compression:

Stored size: 1.16 KB

Contents

module OAuth2
  module Auth
    module Server
      module Endpoints
        class Token

          def call(env)
            authenticator.call(env)
          end

          private

          def authenticator
            Rack::OAuth2::Server::Token.new do |req, res|
              client = Client.find_by_identifier(req.client_id) || req.invalid_client!
              client.secret == req.client_secret || req.invalid_client!
              case req.grant_type
                when :authorization_code
                  req.unsupported_grant_type!
                when :password
                  req.unsupported_grant_type!
                when :client_credentials
                  # scope is a list of space delimited scopes. Rack::OAuth2 converts to an array.
                  res.access_token = client.access_tokens.create(:scope => req.scope).to_bearer_token
                when :refresh_token
                  req.unsupported_grant_type!
                else
                  # NOTE: extended assertion grant_types are not supported yet.
                  req.unsupported_grant_type!
              end
            end
          end

        end
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
oauth2-auth-server-0.0.2 lib/oauth2-auth-server/endpoints/token.rb