Sha256: 8d2b57a06364e40dd977d0ab5f38818304aef01538a3ad5297aa14b1b91a28b9

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.1 lib/oauth2-auth-server/endpoints/token.rb