Aura.Auth icon indicating copy to clipboard operation
Aura.Auth copied to clipboard

Aura.Session compatibility

Open cxj opened this issue 8 years ago • 12 comments

It would be nice if Aura.Auth was "plug compatible" with Aura.Session, so that the included session management could be easily replaced and enhanced by the more featured Aura.Session.

cxj avatar Jun 29 '17 23:06 cxj

I think that would mean separate interface packages and therefore 3.x bump.

jakejohns avatar Jun 29 '17 23:06 jakejohns

Yes, if it breaks compatibility, it'd have bump to a new major version. I'm ok with that. ;-)

cxj avatar Jun 30 '17 03:06 cxj

@cxj looking for this now ?

https://github.com/friendsofaura/FOA.Auth_Session_Bundle ( 3 years old, so not sure if all is working as expected. Have not tested those now )

There is already one ;-) .

harikt avatar Jun 30 '17 04:06 harikt

I think if Aura.Auth just used a compatible API (PHP interface) to its included Session class, then users of it could optionally and easily plug in Aura.Session to get its greater functionality. That would allow Aura.Auth to remain a standalone and not be dependent on anything.

cxj avatar Jun 30 '17 15:06 cxj

@cxj I do agree. See discussion on google group regarding the topic : https://groups.google.com/d/msg/auraphp/dVpSOV6RnM4/HWynJROLm-gJ .

harikt avatar Jun 30 '17 16:06 harikt

It appears that Aura.Session's SegmentInterface and Aura.Auth's SegmentInterface are currently 100% compatible, with Aura.Auth's being a subset of the Aura. Session's.

Aura.Auth:

$ fgrep function SegmentInterface.php     
    public function get($key, $alt = null);
    public function set($key, $val);

Aura.Session:

$ fgrep function SegmentInterface.php
    public function get($key, $alt = null);
    public function set($key, $val);
    public function clear();
    public function setFlash($key, $val);
    public function getFlash($key, $alt = null);
    public function clearFlash();
    public function getFlashNext($key, $alt = null);
    public function setFlashNow($key, $val);
    public function clearFlashNow();
    public function keepFlash();

cxj avatar Aug 17 '19 22:08 cxj

Aura.Session strangely does not have an interface definition for the Session class, while Aura.Auth does. However, the Aura\Session\Sesssion class appears to be compatible with Aura\Auth\Session\SessionInterface.

Aura\Auth:

$ fgrep function SessionInterface.php     
    public function start();
    public function resume();
    public function regenerateId();

Aura\Session:

$ fgrep 'public function' Session.php
    public function __construct(
    public function setDeleteCookie($delete_cookie)
    public function getSegment($name)
    public function isResumable()
    public function isStarted()
    public function start()   // match
    public function resume()  // match
    public function clear()
    public function commit()
    public function destroy()
    public function getCsrfToken()
    public function setCacheExpire($expire)
    public function getCacheExpire()
    public function setCacheLimiter($limiter)
    public function getCacheLimiter()
    public function setCookieParams(array $params)
    public function getCookieParams()
    public function getId()
    public function regenerateId()  // match
    public function setName($name)
    public function getName()
    public function setSavePath($path)
    public function getSavePath()

cxj avatar Aug 17 '19 22:08 cxj

A problem might be the constructors for the Session class. Perhaps some clever use of a Dependency Injection Container might solve this, however. Aura.Auth:

    public function __construct(array $cookie)

Aura.Session:

    public function __construct(
        SegmentFactory $segment_factory,
        CsrfTokenFactory $csrf_token_factory,
        Phpfunc $phpfunc,
        array $cookies = array(),
        $delete_cookie = null
    )

cxj avatar Aug 17 '19 22:08 cxj

Another problem is that Auth\Auth\AuthFactory takes a Segment in its constructor, while Aura\Session\Session expects to generate its own Segments using a SegmentFactory:

    public function __construct(
        array $cookie,
        SessionInterface $session = null,
        SegmentInterface $segment = null
    )

cxj avatar Aug 17 '19 22:08 cxj

Constructor is never a problem if the interfaces satisfies. We can create a separate interface package as https://github.com/auraphp/Aura.Filter_Interface . And this doesn't need all those methods, but very limited / commonly used. Rest of it can be in package level itself.

harikt avatar Aug 18 '19 00:08 harikt

It does not appear that Aura\Filter makes use of Aura\Filter_Interface. For an interface package to be useful, don't we need to have implementations which actually conform to it by using the PHP implements keyword?

If I understand correctly, to do what you are suggesting, there needs to be a new auraphp package named Aura.Session_Interface, correct? If so, can you create that? I do not have commit access to the auraphp project.

Or perhaps there should be just one auraphp Interfaces repository, where interfaces for all of the subprojects are defined. For example: auraphp/Interfaces contains:

  • Aura\Interfaces\Filter_Interface
  • Aura\Interfaces\FailureCollectionInterface
  • Aura\Interfaces\Payload_Interface
  • Aura\Interfaces\Session_Interface
  • Aura\Interfaces\Segment_Interface

Then Aura\Auth\Session could implement Aura\Interfaces\Session_Interface, etc.

cxj avatar Aug 18 '19 15:08 cxj

May be we need to ping @pmjones regarding the thoughts expressed here. So he can create the repository. I don't have access for it.

harikt avatar Aug 19 '19 06:08 harikt