-
Notifications
You must be signed in to change notification settings - Fork 1
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
[refactor] Simplify module #12
Conversation
OAuth1とOAtuh2でModuleクラスを分ける方向で実装してみました。 @koriym どうでしょうか?結構すっきりしたと思います。 使い方としては↓のようになります。 Install Module use OAuth\OAuth2\Service\Facebook;
use Ray\Di\AbstractModule;
use Ray\OAuthModule\OAuth1Module;
use Ray\OAuthModule\OAuth1Service;
use Ray\OAuthModule\OAuth2Module;
use Ray\OAuthModule\OAuth2Service;
class AppModule extends AbstractModule
{
protected function configure()
{
// install oauth1 module (for twitter)
$this->install(new OAuth1Module(OAuth1Service::TWITTER, '{CONSUMER_KEY}', '{CONSUMER_SECRET}', '/callback/twitter', ['force_login' => 'true']);
// install oauth2 module (for facebook)
$this->install(new OAuth2Module(OAuth2Service::FACEBOOK, '{CONSUMER_KEY}', '{CONSUMER_SECRET}', '/callback/facebook', [Facebook::SCOPE_READ_STREAM], ['auth_type' => 'reauthenticate']);
}
} 各ソーシャルサービスの認証画面にリダイレクトする処理 use Ray\OAuthModule\Inject\TwitterOAuthClientInject;
use Ray\OAuthModule\Inject\FacebookOAuthClientInject;
class RedirectController
{
use TwitterOAuthClientInject;
use FacebookOAuthClientInject;
public function twitterAction()
{
// redirect to twitter authorization page
$this->twitterOAuthClient->authorize();
exit;
}
public function facebookAction()
{
// redirect to facebook authorization page
$this->facebookOAuthClient->authorize();
exit;
}
} 認証完了後、ソーシャルサービスからコールバックされる処理 use Ray\OAuthModule\Inject\TwitterOAuthClientInject;
use Ray\OAuthModule\Inject\FacebookOAuthClientInject;
class CallbackController
{
use TwitterOAuthClientInject;
use FacebookOAuthClientInject;
public function twitterAction()
{
$oauthToken = $_GET['oauth_token'];
$oauthVerifier = $_GET['oauth_verifier'];
// get Access Token
$token = $this->twitterOAuthClient->requestAccessToken($oauthToken, $oauthVerifier);
:
:
}
public function facebookAction()
{
$code = $_GET['code'];
// get Access Token
$token = $this->facebookOAuthClient->requestAccessToken($code);
:
:
}
} |
良くなりましたね! |
細かいですけど |
そうですね。そのほうがシンプルでいいと思います。 |
引き続きOAuth2の実装も進めていきます |
👍 |
@koriym 全ての作業が完了しました。問題なければv2.0としてリリースしたいと思います。どうでしょうか |
お疲れ様です! |
@koriym OAuthのdemo追加しました↑ |
いい感じですね |
#11 の続きのPR
#11 (comment)
#11 (comment)