いつも大変お世話になっております。
oAuth2を使うシステムを作っていて、
下記の(1)〜(4)の動作の一連の実装&検証済みですが、
(3)において、10秒ではなく、1日後にアクセスした場合、
再度ID/PWのログイン画面が表示されてしまいます。
このログインID/PWが表示されないようにしたいのです。
'-----------------------------------------
(1)A君がサイトB内のリンクをクリック。サイトAに遷移。
(2)サイトAは、サイトBにoAuth2リクエストをします。
サイトBのログイン画面が表示されるので、
サイトBのID/PWを入力。その後、権限付与許可を行います。
サイトAは、上記で発行されたアクセストークンを元に、
サイトBのデータを取得し、それを元にレポート作成します。
(3)10秒ほど間隔をおいて、A君はふたたび(1)と同じリンククリック
(4)(2)で権限をもらっているので、ログインID/PWをつかってログインすることなく、レポートが作成される。
'-----------------------------------------
ソースは、https://github.com/thephpleague/oauth2-clientのコードを使っていますが、どの部分を改修すればよいでしょうか。
$provider = new \League\OAuth2\Client\Provider\GenericProvider([ 'clientId' => 'demoapp', // The client ID assigned to you by the provider 'clientSecret' => 'demopass', // The client password assigned to you by the provider 'redirectUri' => 'http://example.com/your-redirect-url/', 'urlAuthorize' => 'http://brentertainment.com/oauth2/lockdin/authorize', 'urlAccessToken' => 'http://brentertainment.com/oauth2/lockdin/token', 'urlResourceOwnerDetails' => 'http://brentertainment.com/oauth2/lockdin/resource' ]); // If we don't have an authorization code then get one if (!isset($_GET['code'])) { // Fetch the authorization URL from the provider; this returns the // urlAuthorize option and generates and applies any necessary parameters // (e.g. state). $authorizationUrl = $provider->getAuthorizationUrl(); // Get the state generated for you and store it to the session. $_SESSION['oauth2state'] = $provider->getState(); // Redirect the user to the authorization URL. header('Location: ' . $authorizationUrl); exit; // Check given state against previously stored one to mitigate CSRF attack } elseif (empty($_GET['state']) || ($_GET['state'] !== $_SESSION['oauth2state'])) { unset($_SESSION['oauth2state']); exit('Invalid state'); } else { try { // Try to get an access token using the authorization code grant. $accessToken = $provider->getAccessToken('authorization_code', [ 'code' => $_GET['code'] ]); // We have an access token, which we may use in authenticated // requests against the service provider's API. echo $accessToken->getToken() . "\n"; echo $accessToken->getRefreshToken() . "\n"; echo $accessToken->getExpires() . "\n"; echo ($accessToken->hasExpired() ? 'expired' : 'not expired') . "\n"; // Using the access token, we may look up details about the // resource owner. $resourceOwner = $provider->getResourceOwner($accessToken); var_export($resourceOwner->toArray()); // The provider provides a way to get an authenticated API request for // the service, using the access token; it returns an object conforming // to Psr\Http\Message\RequestInterface. $request = $provider->getAuthenticatedRequest( 'GET', 'http://brentertainment.com/oauth2/lockdin/resource', $accessToken ); } catch (\League\OAuth2\Client\Provider\Exception\IdentityProviderException $e) { // Failed to get the access token or user details. exit($e->getMessage()); } }
お手数をお掛けしますが、何卒、よろしくお願い致します。
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
退会済みユーザー
2016/05/28 16:38