Improvement suggestions
MartinMystikJonas opened this issue · comments
Martin Mystik Jonáš commented
Hi, I just checked this package or use in our projects. I have few suggestions how to improve it. I can create PRs with them if you like it.
- Instead of re-setting redirectUri globally throught
Provider
it is possible to pass it as parameter togetAuthorizationUrl
.
$this->presenter->redirectUrl($this->flow->getAuthorizationUrl([
'redirect_uri' => $this->presenter->link('//:Sign:googleAuthorize')
]));
I think it should be preffered way instead of current:
$this->flow->getProvider()->setRedirectUri(
$this->presenter->link('//:Sign:googleAuthorize')
);
$this->presenter->redirectUrl($this->flow->getAuthorizationUrl());
It should be updated in docs.
- I believe setting $redirectUri is always part of
getAuthorizationUrl
so I suggest it should be optional parameter. To keep BC it should still accept array of options. I suggest to support
getAuthorizationUrl($options) // current signature - will still work if first parameter is array
getAuthorizationUrl($redirectUri) // if first parameter is istring
getAuthorizationUrl($redirectUri, $options)
- Add DI extensions for Facebook and Google that will set up services by simple config
extensions:
google: Contributte\OAuth2Client\DI\Nette\GoogleExtension
google:
clientId: "..."
clientSecret: "..."
- Maybe also add generic
GoogleLogin
andFacebookLogin
controls with basic control logic as described in docs with customizable template (to draw login link) andonAuthorized
onFailure
callbacks for simple use in presenter like:
public function createComponentGoogleBUtton()
{
$googleLogin = new \Contributte\OAuth2Client\Controls\GoogleLogin($this->googleLoginFlow);
$googleLogin->setTemplate("googleButton.latte");
$googleLogin->setRedirectUri($this->link('//:Sign:googleAuthorize'));
$googleLogin->onAuthenticate[] = function(GoogleUser $user) {
$this->authenticator->loginByGoogle($user);
};
}
public function actionGoogleAuthorize(): void
{
$this['googleButton']->authorize();
}
Milan Felix Šulc commented
Hi @MartinMystikJonas. Totally agree. Can you prepare PR? Some tests would be also great.
Martin Mystik Jonáš commented
I will prepere PR