Skip to content

Commit

Permalink
rake taks to generate jwt. #484
Browse files Browse the repository at this point in the history
  • Loading branch information
Martin Fenner committed Apr 23, 2020
1 parent e21f7dc commit bb441c0
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
1 change: 1 addition & 0 deletions app/models/concerns/authenticable.rb
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,7 @@ def generate_token(attributes={})
client_id: attributes.fetch(:client_id, nil),
role_id: attributes.fetch(:role_id, "staff_admin"),
password: attributes.fetch(:password, nil),
beta_tester: attributes.fetch(:beta_tester, nil),
aud: Rails.env,
iat: Time.now.to_i,
exp: Time.now.to_i + attributes.fetch(:exp, 30)
Expand Down
22 changes: 22 additions & 0 deletions lib/tasks/user.rake
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# frozen_string_literal: true

namespace :user do
desc "Generate jwt"
task :generate_jwt => :environment do
attributes = {
uid: ENV['UID'] || "admin",
name: ENV['NAME'] || "Admin",
role_id: ENV['ROLE_ID'] || "staff_admin",
provider_id: ENV['PROVIDER_ID'],
client_id: ENV['CLIENT_ID'],
beta_tester: ENV['BETA_TESTER'],
email: ENV['EMAIL'],
exp: (ENV['DAYS'] || "365").to_i.days,
aud: ENV['AUD'] || Rails.env
}

token = User.generate_token(attributes)
puts attributes.inspect + "\n\n"
puts token
end
end

0 comments on commit bb441c0

Please sign in to comment.