我知道基本身份验证如何在Laravel上注册/登录。但是,我想学习如何设置用户注册(密码授予)。我设置了Passport(2.0) - Passport Grant,我可以得到令牌;但是我找不到用户注册的任何内容。然后我发现topic here解释说我应该在内部调用project_root/
,但也无法弄清楚如何完全实现它。
所以我认为在控制器中创建一个oauth/token
方法并自己处理用户注册,但是我如何将必要的数据传递给signup()
路由?因为Laravel用于oauth/token
的是$request
,但Passport使用的是Request $request
,当我在ServerRequestInterface $request
的issueToken方法上对$ request进行vardump时,它完全不同{{1} }}
oauth/token
Someone did it likes this here,但不知道我应该如何完全实现这种方法。因为我的Request $request
路由的post方法issueToken()是这样的:
// Setup new method
public function signup(Request $request) {
// do validations
// create user
User::create([
'email' => $request->username,
'password' => bcrypt($request->password),
]);
$client = \Laravel\Passport\Client::where('password_client', 1)->first();
$oauthData = [
'grant_type' => 'password',
'client_id' => $client->id,
'client_secret' => $client->secret,
'username' => $request->email,
'password' => $request->password,
'scope' => null
]
// Here, I got confused how to pass this `oauthData` to `issueToken()` route
// and it takes it as `ServerRequestInterface $request`
}
我很困惑,无法弄清楚如何克服这个问题。处理这种情况的正确方法是什么,我需要通过api注册用户?