PHP code example of webteractive / laravel-passwordless
1. Go to this page and download the library: Download webteractive/laravel-passwordless library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
webteractive / laravel-passwordless example snippets
use Webteractive\Passwordless\Facades\Passwordless;
Passwordless::resolveSocialUserUsing(function (string $provider, $oauth, $container) {
// return an app user, or null to deny
return User::firstOrCreate(['email' => $oauth->getEmail()], ['name' => $oauth->getName()]);
});
// config/passwordless.php
'strategies' => [
'magic_code' => [
'enabled' => true,
'ttl' => 15 * 60, // shared TTL for BOTH the link and the code
'same_browser' => true, // enforced on the LINK path only
'code' => ['length' => 6],
],
],
use Webteractive\Passwordless\Facades\Passwordless;
Passwordless::magicCode()->send('[email protected]');
// What the package checks, in effect:
class_exists(Laravel\Fortify\Fortify::class)
&& in_array(TwoFactorAuthenticatable::class, class_uses_recursive($user))
&& $user->hasEnabledTwoFactorAuthentication()
if (Passwordless::twoFactor()->ctor()->challenge($user, $request, $remember);
}
Fortify::confirmPasswordsUsing(function ($user, $password) {
// Users who DO have a password keep the normal path.
if ($password && $user->getAuthPassword() && Auth::guard(config('fortify.guard'))->validate([
Fortify::username() => $user->{Fortify::username()},
'password' => $password,
])) {
return true;
}
return Passwordless::confirmation()->verify($user, (string) $password);
});
Passwordless::twoFactor()->>challenge($user, $request, $remember); // Response — hands off to Fortify
Passwordless::confirmation()->send($user); // emails a confirmation code
Passwordless::confirmation()->verify($user, $code); // bool — Fortify-callback shaped
use Webteractive\Passwordless\Contracts\LoginCodeChannel;
class SmsChannel implements LoginCodeChannel
{
public function send(mixed $user, string $email, string $code, array $context = []): void
{
// Twilio, Vonage, etc.
}
}
// Register it in a service provider:
$this->app->bind('passwordless.login_code_channels.sms', SmsChannel::class);