authentication_resource.rb 703 Bytes
Newer Older
1
2
3
4
5
6
module Dspace
  module Resources
    class AuthenticationResource < ResourceKit::Resource

      resources do
        default_handler(400) { raise InvalidTokenError, 'Invalid access token.' }
7
        default_handler(403) { raise InvalidCredentialsError, 'Wrong Dspace credentials.' }
8
9
10
11
12
13
14
15
16
17
18
19
20
21

        action :login, 'POST /rest/login' do
          body { |email, password| JSON.generate({email: email, password: password}) }
          handler(200, 201) { |response| access_token = response.body }
        end

        action :logout, 'POST /rest/logout' do
          body { |object| JSON.generate(object.to_h) }
          handler(200, 201, 203, 204) { |response| true }
        end
      end

    end
  end
22
end