Skip to content

Enabling Authorization In Willow Sword

Anusha Ranganathan edited this page Nov 13, 2018 · 6 revisions

Steps to authorize all incoming requests to the sword engine

  1. 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.

  2. 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
    
  3. 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!
    
  4. 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.