Class: API::ZoteroController

Inherits:
ApplicationController
  • Object
show all
Defined in:
app/controllers/api/zotero_controller.rb

Overview

Adds the ability to authenticate against Zotero’s OAuth endpoint

Instance Method Summary collapse

Instance Method Details

#callbackObject



20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'app/controllers/api/zotero_controller.rb', line 20

def callback
  access_token = current_token.get_access_token(oauth_verifier: params['oauth_verifier'])
  # parse userID and API key out of token and store in user instance
  current_user.zotero_userid = access_token.params[:userID]
  current_user.save
  Sufia.queue.push(Sufia::Arkivo::CreateSubscriptionJob.new(current_user.user_key))
  redirect_to sufia.profile_path(current_user), notice: 'Successfully connected to Zotero!'
rescue OAuth::Unauthorized
  redirect_to sufia.edit_profile_path(current_user.to_param), alert: 'Please re-authenticate with Zotero'
ensure
  current_user.zotero_token = nil
  current_user.save
end

#initiateObject



10
11
12
13
14
15
16
17
18
# File 'app/controllers/api/zotero_controller.rb', line 10

def initiate
  request_token = client.get_request_token(oauth_callback: callback_url)
  session[:request_token] = request_token
  current_user.zotero_token = request_token
  current_user.save
  redirect_to request_token.authorize_url(identity: '1', oauth_callback: callback_url)
rescue OAuth::Unauthorized
  redirect_to root_url, alert: 'Invalid Zotero client key pair'
end