AnswerBun.com

Laravel Auth Guard Users From Array

Stack Overflow Asked by GSTAR on December 18, 2020

I am building an API which will use token based authentication, I was wondering is it possible to (temporarily) use credentials from a simple predefined array of username => token?.

Here is what I have at the moment:

routesapi.php:

Route::middleware('auth:api')->get('/user', function (Request $request) {
    return $request->user();
});

configauth.php:

'guards' => [
    'api' => [
        'driver' => 'token',
        'provider' => 'users',
        'hash' => false,
    ],
],

'providers' => [
    'users' => [
        'driver' => 'eloquent',
        'model' => AppModelsUser::class,
    ],
],

Now instead of using Eloquent, or a database, can it use a simple PHP array? So essentially I will just have something like:

$users = [
    'john' => 'token_for_john',
    'bob' => 'token_for_bob',
];

And then somewhere in my code I can pass in a username & token combination to authenticate? As I mentioned this is only a temporary measure before I decide on the right token based solution.

Add your own answers!

Related Questions

Use of & operator in C++ Range Based Loop ..Confusing

2  Asked on December 22, 2021 by dmitriy-burtsev

   

‘for’ loop does not loop correctly

3  Asked on December 22, 2021

   

Traditional way of doing asnyc method in javascript

2  Asked on December 22, 2021 by faridavesko

     

How to compare using base class in derived class data

2  Asked on December 22, 2021 by sao-haruka

   

is it possible to use inline if with react components?

2  Asked on December 22, 2021 by handsome

 

Some questions about __init__.py

2  Asked on December 22, 2021 by theabc50111

   

Loop logic, stuck inside a infinite loop

2  Asked on December 22, 2021 by isythnic

     

WHY THE FUNCTION IS RETURNING NaN

3  Asked on December 22, 2021 by user13986133

   

How would one call getCurrentPosition() every second?

1  Asked on December 22, 2021 by user11965730

 

Submit button for multiple choice without using radio button

1  Asked on December 22, 2021 by rizki-prastyo

       

Can I get help formatting my future dates javascript?

2  Asked on December 22, 2021 by aiya-siddig

 

Python extract files from zip

1  Asked on December 22, 2021 by the-x-and-d

     

How can I make Electron channels more type safe?

1  Asked on December 22, 2021 by user1283776

   

Ask a Question

Get help from others!

© 2022 AnswerBun.com. All rights reserved. Sites we Love: PCI Database, MenuIva, UKBizDB, Menu Kuliner, Sharing RPP