drmg17928 2017-12-28 04:54
浏览 614

没有用户模型的Laravel JWT身份验证

I'm trying to build a laravel application and API for mobile users in the same project. The main web is actually a backend of a website and require proper authentication that I have already implemented. And the api also need to authenticate but with different credentials (not user model from web).

At this point I have added dingo api in my project and its working fine. But now I also need to add jwt for dingo. Problem is jwt works with App\User Model by default and I don't want to authenticate api users with web user credentials. Please suggest me what is the best way to work this out. Thanks

  • 写回答

1条回答 默认 最新

  • drhwb470572 2017-12-28 05:05
    关注

    Looking over the docs its looks like you specify the auth provider in the config.php file that get published with php artisan vendor:publish

    Set the auth to your provider: https://github.com/tymondesigns/jwt-auth/blob/develop/config/config.php#L252

    Or you can specify which driver and/or user provider you are using in the app.php config file:

    https://github.com/laravel/laravel/blob/master/config/auth.php#L69 https://github.com/laravel/laravel/blob/master/config/auth.php#L70

    Update:

    1. Make migration to hold clients table: php artisan make:migration create_clients_table

    2. Update the migration file as desired.

    3. Create the Clients model with php artisan make:model Client

    4. Update the model to match the migration and add any relationships.

    5. Run the migration.

    That should make it so this will work

    You may need to update accordingly to something like:

    'api' => [
        'driver' => 'token',
        'provider' => 'clients',
    ],
    

    or possibly:

    'api' => [
        'driver' => 'token',
        'provider' => 'jwt',
    ],
    

    https://github.com/laravel/laravel/blob/master/config/auth.php#L46

    评论

报告相同问题?

悬赏问题

  • ¥20 我想使用一些网络协议或者部分协议也行,主要想实现类似于traceroute的一定步长内的路由拓扑功能
  • ¥30 深度学习,前后端连接
  • ¥15 孟德尔随机化结果不一致
  • ¥15 apm2.8飞控罗盘bad health,加速度计校准失败
  • ¥15 求解O-S方程的特征值问题给出边界层布拉休斯平行流的中性曲线
  • ¥15 谁有desed数据集呀
  • ¥20 手写数字识别运行c仿真时,程序报错错误代码sim211-100
  • ¥15 关于#hadoop#的问题
  • ¥15 (标签-Python|关键词-socket)
  • ¥15 keil里为什么main.c定义的函数在it.c调用不了