-
Notifications
You must be signed in to change notification settings - Fork 9
Enabling Authorization In Willow Sword
-
Enable the feature
Enable this feature by setting
config.authorize_request = true
in your sword config file. By default, this feature is not enabled. See configuration options. -
Add api_key to the user model
The user model in your rails application needs the column api_key to store the api keys. Run a rails migration to add this column and then migrate the database
bundle exec rails generate migration add_api_key_to_users api_key:string:index bundle exec rails db:migrate
-
Generate an api key for all required user account
For users to whom you wish to grant access to the sword endpoint, generate an api key for their user accounts. For example
require 'securerandom' u = User.find_by_email('hyrax@testinstance') u.api_key = SecureRandom.uuid u.save!
-
Ask users to add the Api-key header in all their requests to sword
All requests to the sword endpoint needs to also have the api key in the header. If not they will receive a HTTP 301 error
The header to include is
Api-key
containing the value of the key. The usage documentation has details.