lundi 23 avril 2018

Where are access tokens saved? Laravel5 Passport

In trying to figure out how to integrate Laravel Passport. I installed Passport and migrated database. I can see a table called oauth_access_tokens with these fields:

id 
user_id
client_id
name
scopes
revoked
created_at
updated_at
expired_at

However, where's the token itself? what I have in mind is to compare the expired_at with current time and only issue a new token if the current one is expired.

I thought the token is the id because it's quit long. Thus, I built this function:

public function getToken($id) {
    $access_token = DB::table('oauth_access_tokens')->where('user_id', $id)->first();

    if ($access_token->expires_at >= Carbon::now()) {
        $access_token = $this->createToken('My API')->accessToken;
        DB::table('oauth_access_tokens')->where('user_id', $id)->update(['id' => $access_token]);
    }

    else {
        $access_token = $access_token->id;
    }

    return $access_token;

}

However, I couldn't updated the token because it's too long for the field. (I switched the time comparison to test the update)



from Newest questions tagged laravel-5 - Stack Overflow https://ift.tt/2qSphR4
via IFTTT

Aucun commentaire:

Enregistrer un commentaire