Commit 7e1545e1 authored by Bruno Nocera Zanette's avatar Bruno Nocera Zanette
Browse files

fix Cookie Auth on requests

parent 77d16ff3
......@@ -4,10 +4,11 @@ gemspec
gem 'json'
gem 'resource_kit'
gem 'faraday'
gem 'faraday-cookie_jar'
gem 'net-http-persistent'
gem 'activesupport'
group :development, :spec do
gem 'minitest', '~> 5.8.3'
gem 'rspec'
end
\ No newline at end of file
end
require 'faraday-cookie_jar'
module Dspace
class Client
DSPACE_API = 'https://demo.dspace.org'
......@@ -12,6 +14,7 @@ module Dspace
def connection
Faraday.new(connection_options) do |req|
req.use :cookie_jar
req.request :multipart
req.request :url_encoded
req.use(Faraday::Response::Logger, @logger) unless @logger.nil?
......@@ -51,6 +54,10 @@ module Dspace
@access_token = nil
end
def status
resource(:authentication).status
end
private
def resource(name)
......@@ -62,16 +69,15 @@ module Dspace
def connection_options
{
url: @dspace_api || DSPACE_API,
ssl: {
verify: false
},
headers: {
content_type: 'application/json',
accept: 'application/json',
'rest-dspace-token' => access_token.to_s,
user_agent: "dspace-rest-client #{Dspace::VERSION}"
}
url: @dspace_api || DSPACE_API,
ssl: {
verify: false
},
headers: {
content_type: 'application/json',
accept: 'application/json',
user_agent: "dspace-rest-client #{Dspace::VERSION}"
}
}
end
end
......
......@@ -9,13 +9,17 @@ module Dspace
action :login, 'POST /rest/login' do
query_keys :email, :password
handler(200, 201) { |response| response.inspect }
handler(200, 201) { |response| response['set-cookie'] }
end
action :logout, 'POST /rest/logout' do
body { |object| JSON.generate(object.to_h) }
handler(200, 201, 203, 204) { |response| true }
end
action :status, 'GET /rest/status' do
handler(200, 201, 203, 204) { |response| response.body }
end
end
end
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment