-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' into enh/space-membership-attributes
- Loading branch information
Showing
88 changed files
with
6,058 additions
and
4,895 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
name: PHP Codeception Tests - next | ||
|
||
on: | ||
push: | ||
schedule: | ||
- cron: "0 0 * * 0" | ||
|
||
jobs: | ||
tests: | ||
uses: humhub/actions/.github/workflows/module-tests-next.yml@main | ||
with: | ||
module-id: rest |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
<?php | ||
/** | ||
* @link https://www.humhub.org/ | ||
* @copyright Copyright (c) 2023 HumHub GmbH & Co. KG | ||
* @license https://www.humhub.com/licences | ||
*/ | ||
|
||
namespace humhub\modules\rest\components\auth; | ||
|
||
use Yii; | ||
use yii\db\Expression; | ||
use yii\filters\auth\HttpBearerAuth; | ||
use yii\helpers\StringHelper; | ||
use humhub\modules\rest\models\ImpersonateAuthToken; | ||
use humhub\modules\user\models\User; | ||
use Firebase\JWT\JWT; | ||
|
||
class ImpersonateAuth extends HttpBearerAuth | ||
{ | ||
public $pattern = '/^Impersonate\s+(.*?)$/'; | ||
|
||
public function authenticate($user, $request, $response) | ||
{ | ||
$authHeader = $request->getHeaders()->get($this->header); | ||
|
||
if ($authHeader !== null) { | ||
if ($this->pattern !== null) { | ||
if (preg_match($this->pattern, $authHeader, $matches)) { | ||
$authHeader = $matches[1]; | ||
} else { | ||
return null; | ||
} | ||
|
||
if (!StringHelper::startsWith($authHeader, 'impersonated-')) { | ||
return null; | ||
} | ||
} | ||
|
||
$accessToken = ImpersonateAuthToken::find() | ||
->where(['token' => $authHeader]) | ||
->andWhere(['>', 'expiration', new Expression('NOW()')]) | ||
->one(); | ||
|
||
if ($accessToken && ($identity = $accessToken->user)) { | ||
$user->login($identity); | ||
Yii::$app->user->isImpersonated = true; | ||
} else { | ||
$identity = null; | ||
} | ||
|
||
if ($identity === null) { | ||
$this->challenge($response); | ||
$this->handleFailure($response); | ||
} | ||
|
||
return $identity; | ||
} | ||
|
||
return null; | ||
} | ||
} |
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.