我有一个 Laravel 应用程序,可以从多个客户端访问,所有这些客户端都有自己的域(例如 myclient.com)。此外,还有一个核心客户端(在本示例中使用域 coreclient.org)。
与核心客户端关联的用户能够为任何其他客户端注册用户。
任何其他客户的管理员用户只能为其客户注册用户。
这使用了 Fortify 的基本代码。
当核心客户端为不同的客户端创建新用户时,直到涉及帐户验证电子邮件,这一切都很好。验证电子邮件中的链接使用核心客户端域,而不是新用户所属的客户端。
例如http://coreclient.org/email/verify/1/dd8...8ad?expires=1639608547&signature=718...1ee
它需要是http://myclient.com/email/verify/1/dd8...8ad?expires=1639608547&signature=718...1ee
为了解决这个问题,我在生成后替换了 url 字符串中的域,但这会导致签名无效,因为我假设这是根据创建新用户的人的域生成的。
到目前为止,这是我在 AuthServiceProvider 文件的引导功能中所拥有的……有什么想法吗?
VerifyEmail::createUrlUsing(function ($notifiable) {
$verifyUrl = URL::temporarySignedRoute(
'verification.verify',
Carbon::now()->addMinutes(Config::get('auth.verification.expire', 60)),
[
'id' => $notifiable->getKey(),
'hash' => sha1($notifiable->getEmailForVerification()),
]
);
// This amends the domain in the URL if core client user creating for another client - creates mismatch with signature though
if(auth()->user()->client->is_core && auth()->user()->client_id != $notifiable->client_id) {
$verifyUrl = Str::replace(auth()->user()->client->domains->first()->domain, $notifiable->client->domains->first()->domain, $verifyUrl);
}
return $verifyUrl;
});