Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

Laravel 5.5

I want to change direction of api token that used in TokenGaurd so, i created a custom guard named CafeTokenGaurd extends TokenGuard, i define __construct function into it like what i want, something like this:

public function __construct(UserProvider $provider, Request $request) {
        parent::__construct($provider, $request);
        $this->inputKey = 'api_key'; // I want changing this part
        $this->storageKey = 'api_key';
    }

Now i want to define api_key from relation with users table like this:

device_user table -> token

i want to define specific tokens for each devices user have, and i want to set api key input and storage key to this column in pivot table between users and devices,

how i should this?!

Thanks

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
693 views
Welcome To Ask or Share your Answers For Others

1 Answer

Since the version Laravel 5.7.28, You can simply set up in config/auth.php.

'guards' => [
    'api' => [
        'driver' => 'token',
        'input_key' => 'token',   // The input name to pass through
        'storage_key' => 'token', // The column name to store in database
        'provider' => 'users',
    ],
],

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...