├── src ├── Controllers │ ├── Home.php │ └── Auth │ │ ├── EmailVerificationPromptController.php │ │ ├── EmailVerificationNotificationController.php │ │ ├── ConfirmablePasswordController.php │ │ ├── PasswordResetLinkController.php │ │ ├── VerifyEmailController.php │ │ ├── RegisteredUserController.php │ │ ├── NewPasswordController.php │ │ └── AuthenticatedSessionController.php ├── Contracts │ ├── ResetPasswordInterface.php │ ├── PasswordBrokerFactoryInterface.php │ ├── VerifyEmailInterface.php │ ├── AuthenticationBasicInterface.php │ ├── HasherInterface.php │ ├── AuthorizableInterface.php │ ├── PasswordResetRepositoryInterface.php │ ├── AuthenticatorInterface.php │ ├── UserProviderInterface.php │ ├── HasAccessTokensInterface.php │ ├── AuthFactoryInterface.php │ ├── PasswordBrokerInterface.php │ ├── AuthenticationInterface.php │ └── GateInterface.php ├── AuthServiceProvider.php ├── Traits │ ├── CanResetPasswordTrait.php │ ├── MustVerifyEmailTrait.php │ ├── AuthorizableTrait.php │ ├── InteractsWithTimeTrait.php │ ├── AuthenticatableTrait.php │ ├── GuardHelperTrait.php │ ├── AuthorizesRequestsTrait.php │ ├── UserProviderTrait.php │ ├── InteractsWithAuthentication.php │ └── HasAccessTokensTrait.php ├── Language │ └── en │ │ ├── Auth.php │ │ └── Passwords.php ├── Authorization │ ├── HandlesAuthorization.php │ ├── Events │ │ └── GateEvaluated.php │ └── Response.php ├── Views │ ├── Auth │ │ ├── messages.php │ │ ├── forgot_password.php │ │ ├── verify_email.php │ │ ├── confirm_password.php │ │ ├── layout.php │ │ ├── reset_password.php │ │ ├── login.php │ │ └── register.php │ └── Email │ │ └── layout.php ├── Filters │ ├── RedirectAuthenticatedFilter.php │ ├── AuthenticationBasicFilter.php │ ├── EmailVerifiedFilter.php │ ├── ConfirmPasswordFilter.php │ ├── AuthorizeFilter.php │ ├── ThrottleFilter.php │ └── AuthenticationFilter.php ├── Passwords │ ├── Hash │ │ ├── AbstractHasher.php │ │ ├── Argon2IdHasher.php │ │ ├── HashManager.php │ │ ├── BcryptHasher.php │ │ ├── AbstractManager.php │ │ └── ArgonHasher.php │ ├── PasswordBrokerManager.php │ ├── RateLimiter.php │ ├── PasswordResetRepository.php │ └── PasswordBroker.php ├── AbstractServiceProvider.php ├── Facades │ ├── RateLimiter.php │ ├── Hash.php │ ├── Passwords.php │ ├── Gate.php │ └── Auth.php ├── Exceptions │ ├── AuthenticationException.php │ └── AuthorizationException.php ├── Notifications │ ├── ResetPasswordNotification.php │ └── VerificationNotification.php ├── Helpers │ ├── auth_helper.php │ ├── Arr.php │ └── Str.php ├── Entities │ ├── User.php │ └── AccessToken.php ├── Commands │ └── AuthClearResetCommand.php ├── Models │ ├── UserModel.php │ └── AccessTokenModel.php ├── Config │ ├── Hashing.php │ ├── Services.php │ └── Auth.php ├── CookieRecaller.php ├── Collectors │ └── AuthCollector.php ├── Database │ └── Migrations │ │ └── 2020-12-28-223112_create_auth_tables.php └── UserDatabase.php ├── LICENSE.md ├── composer.json └── README.md /src/Controllers/Home.php: -------------------------------------------------------------------------------- 1 | 14 | */ 15 | protected static $policies = []; 16 | 17 | /** 18 | * {@inheritdoc} 19 | */ 20 | public static function register() 21 | { 22 | static::registerPolicies(); 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /src/Controllers/Auth/EmailVerificationPromptController.php: -------------------------------------------------------------------------------- 1 | user()->hasVerifiedEmail() 19 | ? redirect()->to(session('intended') ?? config('Auth')->home) 20 | : view('Auth/verify_email'); 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /src/Contracts/PasswordBrokerFactoryInterface.php: -------------------------------------------------------------------------------- 1 | email; 18 | } 19 | 20 | /** 21 | * Send the password reset notification. 22 | * 23 | * @return void 24 | */ 25 | public function sendPasswordResetNotification(string $token) 26 | { 27 | Events::trigger(ResetPasswordInterface::class, $this->getEmailForPasswordReset(), $token); 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /src/Language/en/Auth.php: -------------------------------------------------------------------------------- 1 | 'These credentials do not match our records.', 16 | 'throttler' => 'You submitted over {0} requests within a minute. Please try again in {1} seconds.', 17 | 'throttle' => 'Too many login attempts. Please try again in {0} seconds.', 18 | ]; 19 | -------------------------------------------------------------------------------- /src/Authorization/HandlesAuthorization.php: -------------------------------------------------------------------------------- 1 | has('message')) : ?> 2 |
= session('message') ?>
4 |= session('error') ?>
12 |8 | 11 | Back to log in 12 | 13 |
14 |Don't fret! Just type in your email and we will send you a code to reset your password!
22 | 36 |8 | 11 | Back to homepage 12 | 13 |
14 |22 | Thanks for signing up! Before getting started, could you verify your email address by clicking on 23 | the link we just emailed to you? If you didn't receive the email, we will gladly send you 24 | another. 25 |
26 | 32 | 38 || User ID | #{$user->id} |
| Username | {$user->username} |
| {$user->email} | |
| User since | {$user->created_at->humanize()} |
| Verified at | {$user->email_verified_at} |
Not logged in.
'; 53 | } 54 | 55 | return $html; 56 | } 57 | 58 | /** 59 | * Gets the "badge" value for the button. 60 | * 61 | * @return int|null ID of the current User, or null when not logged in 62 | */ 63 | public function getBadgeValue(): ?int 64 | { 65 | return auth('web')->check() ? auth('web')->id() : null; 66 | } 67 | 68 | /** 69 | * Display the icon. 70 | * 71 | * Icon from https://icons8.com - 1em package 72 | */ 73 | public function icon(): string 74 | { 75 | return 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABgAAAAYCAYAAADgdz34AAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAJcEhZcwAADsMAAA7DAcdvqGQAAADLSURBVEhL5ZRLCsIwGAa7UkE9gd5HUfEoekxxJx7AhXoCca/fhESkJiQxBHwMDG3S/9EmJc0n0JMruZVXK/fMdWQRY7mXt4A7OZJvwZu74hRayIEc2nv3jGtXZrOWrnifiRY0OkhiWK5sWGeS52bkZymJ2ZhRJmwmySxLCL6CmIsZZUIixkiNezCRR+kSUyWH3Cgn6SuQIk2iuOBckvN+t8FMnq1TJloUN3jefN9mhvJeCAVWb8CyUDj0vxc3iPFHDaofFdUPu2+iae7nYJMCY/1bpAAAAABJRU5ErkJggg=='; 76 | } 77 | } 78 | -------------------------------------------------------------------------------- /src/Facades/Auth.php: -------------------------------------------------------------------------------- 1 | {$method}(...$arguments); 60 | } 61 | } 62 | -------------------------------------------------------------------------------- /src/Traits/AuthorizesRequestsTrait.php: -------------------------------------------------------------------------------- 1 | parseAbilityAndArguments($ability, $arguments); 21 | 22 | return Services::gate()->authorize($ability, $arguments); 23 | } 24 | 25 | /** 26 | * Authorize a given action for a user. 27 | * 28 | * @param \Fluent\Auth\Contracts\AuthenticatorInterface $user 29 | * @param mixed $ability 30 | * @param mixed|array $arguments 31 | * @return \Fluent\Auth\Authorization\Response 32 | * 33 | * @throws \Fluent\Auth\Exceptions\AuthorizationException 34 | */ 35 | public function authorizeForUser($user, $ability, $arguments = []) 36 | { 37 | [$ability, $arguments] = $this->parseAbilityAndArguments($ability, $arguments); 38 | 39 | return Services::gate()->forUser($user)->authorize($ability, $arguments); 40 | } 41 | 42 | /** 43 | * Guesses the ability's name if it wasn't provided. 44 | * 45 | * @param mixed $ability 46 | * @param mixed|array $arguments 47 | * @return array 48 | */ 49 | protected function parseAbilityAndArguments($ability, $arguments) 50 | { 51 | if (is_string($ability) && strpos($ability, '\\') === false) { 52 | return [$ability, $arguments]; 53 | } 54 | 55 | $method = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS, 3)[2]['function']; 56 | 57 | return [$this->normalizeGuessedAbilityName($method), $ability]; 58 | } 59 | 60 | /** 61 | * Normalize the ability name that has been guessed from the method name. 62 | * 63 | * @param string $ability 64 | * @return string 65 | */ 66 | protected function normalizeGuessedAbilityName($ability) 67 | { 68 | $map = $this->resourceAbilityMap(); 69 | 70 | return $map[$ability] ?? $ability; 71 | } 72 | 73 | /** 74 | * Get the map of resource methods to ability names. 75 | * 76 | * @return array 77 | */ 78 | protected function resourceAbilityMap() 79 | { 80 | return [ 81 | 'index' => 'viewAny', 82 | 'show' => 'view', 83 | 'new' => 'create', 84 | 'create' => 'create', 85 | 'edit' => 'update', 86 | 'update' => 'update', 87 | 'delete' => 'delete', 88 | ]; 89 | } 90 | } -------------------------------------------------------------------------------- /src/Passwords/Hash/HashManager.php: -------------------------------------------------------------------------------- 1 | config->bcrypt ?? []); 20 | } 21 | 22 | /** 23 | * Create an instance of the Argon2i hash Driver. 24 | * 25 | * @return ArgonHasher 26 | */ 27 | public function createArgonDriver() 28 | { 29 | return new ArgonHasher($this->config->argon ?? []); 30 | } 31 | 32 | /** 33 | * Create an instance of the Argon2id hash Driver. 34 | * 35 | * @return Argon2IdHasher 36 | */ 37 | public function createArgon2idDriver() 38 | { 39 | return new Argon2IdHasher($this->config->argon ?? []); 40 | } 41 | 42 | /** 43 | * Get information about the given hashed value. 44 | * 45 | * @param string $hashedValue 46 | * @return array 47 | */ 48 | public function info($hashedValue) 49 | { 50 | return $this->driver()->info($hashedValue); 51 | } 52 | 53 | /** 54 | * Hash the given value. 55 | * 56 | * @param string $value 57 | * @param array $options 58 | * @return string 59 | */ 60 | public function make($value, array $options = []) 61 | { 62 | return $this->driver()->make($value, $options); 63 | } 64 | 65 | /** 66 | * Check the given plain value against a hash. 67 | * 68 | * @param string $value 69 | * @param string $hashedValue 70 | * @param array $options 71 | * @return bool 72 | */ 73 | public function check($value, $hashedValue, array $options = []) 74 | { 75 | return $this->driver()->check($value, $hashedValue, $options); 76 | } 77 | 78 | /** 79 | * Check if the given hash has been hashed using the given options. 80 | * 81 | * @param string $hashedValue 82 | * @param array $options 83 | * @return bool 84 | */ 85 | public function needsRehash($hashedValue, array $options = []) 86 | { 87 | return $this->driver()->needsRehash($hashedValue, $options); 88 | } 89 | 90 | /** 91 | * Get the default driver name. 92 | * 93 | * @return string 94 | */ 95 | public function getDefaultDriver() 96 | { 97 | return $this->config->driver; 98 | } 99 | } 100 | -------------------------------------------------------------------------------- /src/Filters/AuthenticationFilter.php: -------------------------------------------------------------------------------- 1 | auth = Services::auth(); 27 | $this->response = Services::response(); 28 | } 29 | 30 | /** 31 | * {@inheritdoc} 32 | */ 33 | public function before(RequestInterface $request, $arguments = null) 34 | { 35 | return $this->authenticate($request, $arguments); 36 | } 37 | 38 | /** 39 | * {@inheritdoc} 40 | */ 41 | public function after(RequestInterface $request, ResponseInterface $response, $arguments = null) 42 | { 43 | } 44 | 45 | /** 46 | * Determine if the user is logged in to any of the given guards. 47 | * 48 | * @param RequestInterface $request 49 | * @param array $guards 50 | * @return void 51 | * @throws AuthenticationException 52 | */ 53 | protected function authenticate($request, $guards) 54 | { 55 | if (empty($guards)) { 56 | $guards = [null]; 57 | } 58 | 59 | foreach ($guards as $guard) { 60 | if ($this->auth->guard($guard)->check()) { 61 | return $this->auth->shouldUse($guard); 62 | } 63 | } 64 | 65 | return $this->unauthenticated($request, $guards); 66 | } 67 | 68 | /** 69 | * Handle an unauthenticated user. 70 | * 71 | * @param RequestInterface $request 72 | * @param array $guards 73 | * @return void 74 | * @throws AuthenticationException 75 | */ 76 | protected function unauthenticated($request, $guards) 77 | { 78 | if ($request->isAJAX()) { 79 | return $this->fail('Unauthenticated.', ResponseInterface::HTTP_UNAUTHORIZED); 80 | } 81 | 82 | throw new AuthenticationException( 83 | 'Unauthenticated.', 84 | $guards, 85 | ResponseInterface::HTTP_UNAUTHORIZED, 86 | $this->redirectTo($request) 87 | ); 88 | } 89 | 90 | /** 91 | * Get the path the user should be redirected to when they are not authenticated. 92 | * 93 | * @param RequestInterface $request 94 | * @return string|null 95 | */ 96 | protected function redirectTo($request) 97 | { 98 | } 99 | } 100 | -------------------------------------------------------------------------------- /src/Views/Auth/confirm_password.php: -------------------------------------------------------------------------------- 1 | = $this->extend('Auth/layout') ?> 2 | 3 | = $this->section('content') ?> 4 |8 | 11 | Back to homepage 12 | 13 |
14 |This is a secure area of the application. Please confirm your password before continuing.
22 | 41 |8 | 11 | Back to log in 12 | 13 |
14 |7 | 8 | 11 | Back to homepage 12 | 13 |
14 |
33 |
|
59 |
7 | 8 | 11 | Back to homepage 12 | 13 |
14 |