Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[10.x] Add custom recaller segments callback to SessionGuard #46237

Closed
wants to merge 1 commit into from
Closed

[10.x] Add custom recaller segments callback to SessionGuard #46237

wants to merge 1 commit into from

Conversation

JurianArie
Copy link
Contributor

@JurianArie JurianArie commented Feb 23, 2023

#42316 added support for reading additional segments from the recaller cookie. This allows you to set the segments on creation without having to extend the SessionGuard.

This would allow me to replace my custom guard with just one line: SessionGuard::$customRecallerSegments = fn () => now()->timestamp;

<?php

namespace App\Support\Auth;

use Illuminate\Auth\SessionGuard as Guard;
use Illuminate\Contracts\Auth\Authenticatable;
use Illuminate\Support\Facades\Date;

class SessionGuard extends Guard
{
    /**
     * Get the name of the cookie used to store the "recaller".
     *
     * @return string
     */
    public function getRecallerName(): string
    {
        return 'remember_' . $this->name . '_' . sha1(Guard::class);
    }

    /**
     * Queue the recaller cookie into the cookie jar.
     *
     * @param \Illuminate\Contracts\Auth\Authenticatable $user
     * @return void
     */
    protected function queueRecallerCookie(Authenticatable $user): void
    {
        $this->getCookieJar()->queue($this->createRecaller(vsprintf('%s|%s|%s|%s', [
            $user->getAuthIdentifier(),
            $user->getRememberToken(),
            $user->getAuthPassword(),
            Date::now()->timestamp,
        ])));
    }
}

@JurianArie JurianArie marked this pull request as draft February 23, 2023 12:36
@JurianArie JurianArie marked this pull request as ready for review February 23, 2023 13:18
@taylorotwell
Copy link
Member

Thanks for your pull request to Laravel!

Unfortunately, I'm going to delay merging this code for now. To preserve our ability to adequately maintain the framework, we need to be very careful regarding the amount of code we include.

If possible, please consider releasing your code as a package so that the community can still take advantage of your contributions!

If you feel absolutely certain that this code corrects a bug in the framework, please "@" mention me in a follow-up comment with further explanation so that GitHub will send me a notification of your response.

@JurianArie JurianArie deleted the custom-recaller-segments branch February 25, 2023 12:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants