【问题标题】:Wrong value inserted into oauth_access_token table错误的值插入到 oauth_access_token 表中
【发布时间】:2019-01-04 06:30:05
【问题描述】:

我在我的 Laravel 应用程序中设置 Laravel 护照,当我执行 Request::create/oauth/token 和 Laravel/Passport 只是将我的用户名插入到错误的列 (user_id) 时,它没有按预期工作表oauth_access_tokens

SQLSTATE[22007]:无效的日期时间格式:1366 不正确的整数 值:第 1 行的列“user_id”的“admin”(SQL:插入 oauth_access_tokens (id, user_id, client_id, scopes, revokedcreated_atupdated_atexpires_at) 值 (720b884efdcc52f13bc1af44703fab477eb37731404104b9da90d9c9e9164809c0fe754b74fc6814, 管理员, 2, [], 0, 2019-01-04 06:11:32, 2019-01-04 06:11:32, 2019-01-04 06:26:32))

为了您的信息,我的用户表没有典型的电子邮件/密码。这是我必须构建每个表的模型的现有数据库。所以基本上我的字段名称如下

  • us_username
  • us_password ~ 现有数据库使用 md5 对其进行哈希处理,因此我创建了一个自定义提供程序
  • us_email

这就是我将请求调用到/oauth/token的方式

$data = [
    'grant_type' => 'password',
    'client_id' => $client->id,
    'client_secret' => $client->secret,
    'username' => request('us_username'),
    'password' => request('password'),
    'scope' => '',
];

$reqwest = Request::create('/oauth/token', 'POST', $data);

我希望它像往常一样插入,因为我可以像往常一样通过网络界面登录。

【问题讨论】:

  • user_id 字段要求插入的值是 整数。您正在插入值“管理员”
  • 我没有触发那个电话。这是 Laravel 护照

标签: php mysql laravel laravel-passport laravel-5.7


【解决方案1】:

看起来 $client->id 有一个 'admin' 值..

检查为什么您的 $client->id 值是 admin.. 可能是因为您的输入或数据库中的用户表

【讨论】:

  • 我已经检查过它没有管理员价值。相反,它需要我的用户名值
  • 你试过这个吗? laravel.com/docs/5.7/passport 迁移自定义 如果您不打算使用 Passport 的默认迁移,则应在 AppServiceProvider 的 register 方法中调用 Passport::ignoreMigrations 方法。您可以使用 php artisan vendor:publish --tag=passport-migrations 导出默认迁移。默认情况下,Passport 使用整数列来存储 user_id。如果您的应用程序使用不同的列类型来识别用户(例如:UUID),您应该在发布后修改默认的 Passport 迁移。
猜你喜欢
  • 1970-01-01
  • 2021-12-22
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2020-02-29
  • 2011-03-28
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多