thephpleague / oauth2-client

Easy integration with OAuth 2.0 service providers.

Home Page:http://oauth2-client.thephpleague.com

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Extend type hint for redirect URI

okorneliuk opened this issue · comments

I would like to have the ability to use class implementing \Stringable for redirect URI. If it makes sense, I can create a PR.

This could be one of elegant ways to provide redirect URI:

<?php

namespace App\OAuth2;

use Symfony\Component\Routing\Generator\UrlGeneratorInterface;

class RedirectUri implements \Stringable
{
    private UrlGeneratorInterface $urlGenerator;

    public function __construct(UrlGeneratorInterface $urlGenerator)
    {
        $this->urlGenerator = $urlGenerator;
    }

    public function __toString(): string
    {
        return $this->urlGenerator->generate('oauth2_connect_callback');
    }
}

Closing the issue due to missing polyfills for Stringable for PHP <7.1 and we should support >=5.6. At this point, we can cast to (string) when initialize a provider.