Class: Hyrax::API::ZoteroController

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

Overview

Adds the ability to authenticate against Zotero’s OAuth endpoint

Instance Method Summary collapse

Instance Method Details

#callbackObject



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

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
  Hyrax::Arkivo::CreateSubscriptionJob.perform_later(current_user)
  redirect_to hyrax.dashboard_profile_path(current_user), notice: 'Successfully connected to Zotero!'
rescue OAuth::Unauthorized
  redirect_to hyrax.edit_dashboard_profile_path(current_user.to_param), alert: 'Please re-authenticate with Zotero'
ensure
  current_user.zotero_token = nil
  current_user.save
end

#initiateObject



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

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