API Keys Show Never Used
These API keys have been used but they are showing Never Used. Where is this being updated?
Hey Nick,
Thanks for pointing that out. I've added a fix to make this update when the key is used. You can make this modification inside of: wave\src\Http\Controllers\API\AuthController.php
on line 53, you should find the token()
function:
public function token(){
$request = app('request');
if(isset($request->key)){
$key = \Wave\ApiKey::where('key', '=', $request->key)->first();
if(isset($key->id)){
return response()->json(['access_token' => JWTAuth::fromUser($key->user, ['exp' => config('wave.api.key_token_expires', 1)])]);
} else {
abort('400', 'Invalid Api Key');
}
} else {
abort('401', 'Unauthorized');
}
}
You'll need to update that function with the following:
public function token(){
$request = app('request');
if(isset($request->key)){
$key = \Wave\ApiKey::where('key', '=', $request->key)->first();
if(isset($key->id)){
$key->last_used_at = \Carbon\Carbon::now()->toDateTimeString();
$key->save();
return response()->json(['access_token' => JWTAuth::fromUser($key->user, ['exp' => config('wave.api.key_token_expires', 1)])]);
} else {
abort('400', 'Invalid Api Key');
}
} else {
abort('401', 'Unauthorized');
}
}
You'll see that if the key is valid, we will then update the last_used_at
, with the following code:
$key->last_used_at = \Carbon\Carbon::now()->toDateTimeString();
$key->save();
Let me know if that helps and if you have any other questions.
Appreciate it :)
Thanks Tony.
This really helped.
I went ahead and added that to my API Middleware since we bypassing the JWT calls.
Ok I think there is also in issue with the Blade on both themes.
-
UIKit, I can not update the name of the keys. I also see this error wave.test/settings/type= 500 (Internal Server Error)
-
While this is now updating the database, it is still showing Never Used. This is solved by editing line 34 of partials/api.blade.php
Thanks @nick-jensen,
Would you mind sharing what you have modified. I see the code here:
@if(is_null($apiKey->last_used)){{ 'Never Used' }}@else{{ $apiKey->last_used }}@endif
Which will display Never Used
if it is null, otherwise, it should show the timestamp that it was last used. Let me know and I'll get this updated in the next release.
Appreciate it. Thanks!
They key in the database is last_used_at
@if(is_null($apiKey->last_used_at)){{ 'Never Used' }}@else{{ $apiKey->last_used_at }}@endif