contributte / oauth2-client

:lock: OAuth2 client for Nette Framework

Home Page:https://contributte.org/packages/contributte/oauth2-client.html

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Improvement suggestions

MartinMystikJonas opened this issue · comments

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.

  1. Instead of re-setting redirectUri globally throught Provider it is possible to pass it as parameter to getAuthorizationUrl.
$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.

  1. 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) 
  1. 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: "..."
  1. Maybe also add generic GoogleLogin and FacebookLogin controls with basic control logic as described in docs with customizable template (to draw login link) and onAuthorized 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();
}

Hi @MartinMystikJonas. Totally agree. Can you prepare PR? Some tests would be also great.

I will prepere PR