Skip to content

Commit

Permalink
get challenge
Browse files Browse the repository at this point in the history
  • Loading branch information
ufaboy committed Nov 25, 2023
1 parent a41798d commit 6704504
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 6 deletions.
2 changes: 1 addition & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ services:
build: docker/nginx
container_name: basic-nginx
ports:
- "80:80"
- "8080:8080"
volumes:
- ./:/app
depends_on:
Expand Down
5 changes: 3 additions & 2 deletions docker/nginx/vhost.conf
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
server {

listen 80;
server_name librarydev.site;
listen 8080;
# server_name librarydev.site;
server_name localhost;

root /app/web;
index index.php;
Expand Down
14 changes: 14 additions & 0 deletions modules/api/controllers/AuthController.php
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,20 @@ public function actionSignup() {
]);
}

/**
* @throws \Exception
*/
public function actionChallenge() {
$session = Yii::$app->session;
$challenge = base64_encode(random_bytes(32));
$session->set('challenge', $challenge);
return $challenge;
}
public function actionSignin() {
$session = Yii::$app->session;
return $session['challenge'];
}

/**
* Logout action.
*
Expand Down
4 changes: 1 addition & 3 deletions modules/api/models/User.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,14 @@
use yii\filters\auth\HttpBearerAuth;

class User extends \app\common\models\User {
public function behaviors()
{
public function behaviors() {
$behaviors = parent::behaviors();
$behaviors['authenticator'] = [
'class' => HttpBearerAuth::class,
];
return $behaviors;
}
public function getToken() {

$this->access_token = Yii::$app->getSecurity()->generateRandomString();
$this->save();
return $this->access_token;
Expand Down

0 comments on commit 6704504

Please sign in to comment.