Skip to content

Commit

Permalink
🎁 Add Api-Key auth for WillowSword
Browse files Browse the repository at this point in the history
This commit will add the api_key column to the user model and turn on
authorized requests for WillowSword.  To give a user access, do
something like the following:

```rb
u = User.find_by(email: 'some_user@example.com')
u.api_key = SecureRandom.uuid
u.save!
```

Ref:
  - https://github.com/CottageLabs/willow_sword/wiki/Enabling-Authorization-In-Willow-Sword
  - notch8/palni-palci#1037
  • Loading branch information
kirkkwang committed May 30, 2024
1 parent cc180ba commit aab8006
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 1 deletion.
1 change: 1 addition & 0 deletions config/initializers/willow_sword.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,6 @@
config.collection_models = [Hyrax.config.collection_model]
config.file_set_models = [Hyrax.config.file_set_model]
config.default_work_model = Hyrax.config.curation_concerns.first
config.authorize_request = true
end
end
6 changes: 6 additions & 0 deletions db/migrate/20240530205142_add_api_key_to_users.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
class AddAPIKeyToUsers < ActiveRecord::Migration[6.1]
def change
add_column :users, :api_key, :string
add_index :users, :api_key
end
end
4 changes: 3 additions & 1 deletion db/schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
#
# It's strongly recommended that you check this file into your version control system.

ActiveRecord::Schema.define(version: 2024_05_28_232441) do
ActiveRecord::Schema.define(version: 2024_05_30_205142) do

# These are extensions that must be enabled in order to support this database
enable_extension "hstore"
Expand Down Expand Up @@ -917,6 +917,8 @@
t.string "uid"
t.string "batch_email_frequency", default: "never"
t.datetime "last_emailed_at"
t.string "api_key"
t.index ["api_key"], name: "index_users_on_api_key"
t.index ["email"], name: "index_users_on_email", unique: true
t.index ["invitation_token"], name: "index_users_on_invitation_token", unique: true
t.index ["reset_password_token"], name: "index_users_on_reset_password_token", unique: true
Expand Down

0 comments on commit aab8006

Please sign in to comment.