Project

General

Profile

Programmatic change of ApiKey

Added by Marco Descher over 10 years ago

Hy,

is there a way to programmatically change the ApiKey? I want to do this as a security measurement in regular intervals, and automate this!

Thanks for your help!


Replies (2)

RE: Programmatic change of ApiKey - Added by Marco Descher about 10 years ago

I create a small script, where EMAIL denotes the mail address of the account you want to reset the token upon

# myTokenResetScript
user = User.find_by_mail("EMAIL")
t1 = Token.create(:user => user, :action => 'api')
puts(t1.value)

execute the script using

ruby script/rails runner myTokenResetScript -e production

you will get the new token as output of the script and can act upon it accordingly.

RE: Programmatic change of ApiKey - Added by Marco Descher 10 months ago

In newer versions it works like this

bundle exec rails runner 'user = User.find_by_mail("USER_EMAIL"); user.api_token.destroy; user.reload; puts(user.api_key)'
    (1-2/2)