为了账号安全,请及时绑定邮箱和手机立即绑定

Laravel:验证字段对应于特定行

Laravel:验证字段对应于特定行

PHP
繁星淼淼 2021-04-28 13:22:25
我正在使用护照为我的API建立注册方法。当用户进行注册时,我想将访问令牌还给他,就像我们要求访问令牌时一样。为此,使用授予密码的客户端。我所做的就是要求在登记的数据client_id沿client_secret。然后我正在寻找的是我的验证规则能够验证client_secret对应于client_id。这是我的注册方法:/** * Register a new user in the system. * @param \Illuminate\Http\Request $request * @return \Illuminate\Http\Response */public function register(Request $request){    $vb = User::ValidationBook();    $data = $request->validate($vb["rules"], $vb["messages"]);    // Neccesary data to get a token at registration    $password = $data["user"]["password"];    $clientId = $data["user"]["client_id"];    $clientSecret = $data["user"]["client_secret"];    // If validation passes, create user    $user = $this->userService->store($data);    $request->request->add([        'grant_type'    => 'password',        'client_id'     => $clientId,        'client_secret' => $clientSecret,        'username'      => $user->email,        'password'      => $password,        'scope'         => null,    ]);    // Fire off the internal request.    $token = Request::create(        'oauth/token',        'POST'    );    return \Route::dispatch($token);}这是我的用户模型的简化版本,我拥有验证书方法中的所有规则。class User extends Authenticatable{    /**     * Returns an array that contains two indexes:     * 'rules' for the validation     * 'messages' messages given by the validation     *     * @return array     **/    public static function ValidationBook($except = [], $append = [])    {        $book = ['rules' => [], 'messages' => []];        $book['rules'] = [            ... the other rules            //Extra data for register            'user.client_id' => 'required|exists:oauth_clients,id',            'user.client_secret' => 'required|exists:oauth_clients,secret'        ]; 如何在user.client_secret规则中添加规则以验证机密是否与该特定ID相对应?这可能不是在注册后返回访问令牌的最佳选择,如果有一种简单的避免方法,我将很高兴对此进行了解。
查看完整描述

1 回答

  • 1 回答
  • 0 关注
  • 123 浏览

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信