-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #286 from silinternational/feature/store-access-to…
…ken-in-session store access token in session
- Loading branch information
Showing
18 changed files
with
488 additions
and
271 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
<?php | ||
|
||
namespace common\components\auth; | ||
|
||
use Yii; | ||
use yii\filters\auth\AuthMethod; | ||
use yii\web\UnauthorizedHttpException; | ||
|
||
class HttpOnlyAuth extends AuthMethod | ||
{ | ||
/** | ||
* Authenticates the user based on the access_token stored in the session. | ||
* @param \yii\web\User $user the user object | ||
* @param \yii\web\Request $request the request object | ||
* @param \yii\web\Response $response the response object | ||
* @return \yii\web\IdentityInterface | null the authenticated user identity. If authentication information is not provided, null will be returned. | ||
* @throws UnauthorizedHttpException if authentication information is provided but is invalid. | ||
*/ | ||
public function authenticate($user, $request, $response) | ||
{ | ||
$accessToken = $request->cookies->getValue('access_token'); | ||
|
||
if ($accessToken === null) { | ||
return null; | ||
} | ||
|
||
$identity = $user->loginByAccessToken($accessToken, get_class($this)); | ||
if ($identity === null) { | ||
$this->handleFailure($response); | ||
} | ||
|
||
return $identity; | ||
} | ||
|
||
/** | ||
* @inheritdoc | ||
*/ | ||
public function handleFailure($response) | ||
{ | ||
throw new UnauthorizedHttpException('Your request was made with invalid credentials.'); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.