Skip to content

Commit 23176bb

Browse files
committed
updated_at incremented on use - key reduced to 60 chars
1 parent 04bcdf6 commit 23176bb

File tree

3 files changed

+5
-3
lines changed

3 files changed

+5
-3
lines changed

database/migrations/2019_01_01_000000_create_api_keys_table.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ public function up()
1818
$table->bigInteger('user_id')->index();
1919
$table->string('name', 50);
2020
$table->string('type', 10);
21-
$table->string('api_key', 80)->unique()->nullable()->default(null);
21+
$table->string('api_key', 60)->unique()->nullable()->default(null);
2222
$table->timestamps();
2323
});
2424
}

src/ApiKeyToUserProvider.php

+3
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@ public function retrieveById ($identifier) {
1717
}
1818
public function retrieveByToken ($identifier, $apiKey) {
1919
$apiKey = $this->apiKey->with('user')->where($identifier, $apiKey)->first();
20+
if($apiKey){
21+
$apiKey->touch();
22+
}
2023
return $apiKey && $apiKey->user ? $apiKey->user : null;
2124
}
2225
public function updateRememberToken (Authenticatable $user, $token) {

src/LaravelApiKeys.php

+1-2
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,11 @@ public static function create( $apiKeyType = null, $data = [])
1616
}
1717

1818
$name = isset($data['name']) ? $data['name'] : 'Unnamed Key';
19-
dump($name);
2019

2120
return ApiKey::firstOrCreate([
2221
'user_id' => Auth::id(),
2322
'type' => $apiKeyType,
24-
'api_key' => Str::random(80),
23+
'api_key' => Str::random(60),
2524
'name' => $name,
2625
]);
2726
}

0 commit comments

Comments
 (0)