Skip to content

Commit b908c5b

Browse files
committed
configure User component
1 parent 6c8917b commit b908c5b

File tree

2 files changed

+95
-0
lines changed

2 files changed

+95
-0
lines changed

api/config/components.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,11 @@
55
*/
66

77
return [
8+
'user' => [
9+
'enableSession' => false,
10+
'loginUrl' => null,
11+
'identityClass' => \common\models\ApiUser::class,
12+
],
813
'request' => [
914
'parsers' => [
1015
'application/json' => yii\web\JsonParser::class,

common/models/ApiUser.php

Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
<?php
2+
/**
3+
*
4+
*
5+
* @author Carsten Brandt <mail@cebe.cc>
6+
*/
7+
8+
namespace common\models;
9+
10+
11+
use yii\web\IdentityInterface;
12+
13+
class ApiUser implements IdentityInterface
14+
{
15+
16+
/**
17+
* Finds an identity by the given ID.
18+
* @param string|int $id the ID to be looked for
19+
* @return IdentityInterface the identity object that matches the given ID.
20+
* Null should be returned if such an identity cannot be found
21+
* or the identity is not in an active state (disabled, deleted, etc.)
22+
*/
23+
public static function findIdentity($id)
24+
{
25+
// TODO: Implement findIdentity() method.
26+
return null;
27+
}
28+
29+
/**
30+
* Finds an identity by the given token.
31+
* @param mixed $token the token to be looked for
32+
* @param mixed $type the type of the token. The value of this parameter depends on the implementation.
33+
* For example, [[\yii\filters\auth\HttpBearerAuth]] will set this parameter to be `yii\filters\auth\HttpBearerAuth`.
34+
* @return IdentityInterface the identity object that matches the given token.
35+
* Null should be returned if such an identity cannot be found
36+
* or the identity is not in an active state (disabled, deleted, etc.)
37+
*/
38+
public static function findIdentityByAccessToken($token, $type = null)
39+
{
40+
// TODO: Implement findIdentityByAccessToken() method.
41+
return null;
42+
}
43+
44+
/**
45+
* Returns an ID that can uniquely identify a user identity.
46+
* @return string|int an ID that uniquely identifies a user identity.
47+
*/
48+
public function getId()
49+
{
50+
// TODO: Implement getId() method.
51+
return null;
52+
}
53+
54+
/**
55+
* Returns a key that can be used to check the validity of a given identity ID.
56+
*
57+
* The key should be unique for each individual user, and should be persistent
58+
* so that it can be used to check the validity of the user identity.
59+
*
60+
* The space of such keys should be big enough to defeat potential identity attacks.
61+
*
62+
* This is required if [[User::enableAutoLogin]] is enabled. The returned key will be stored on the
63+
* client side as a cookie and will be used to authenticate user even if PHP session has been expired.
64+
*
65+
* Make sure to invalidate earlier issued authKeys when you implement force user logout, password change and
66+
* other scenarios, that require forceful access revocation for old sessions.
67+
*
68+
* @return string a key that is used to check the validity of a given identity ID.
69+
* @see validateAuthKey()
70+
*/
71+
public function getAuthKey()
72+
{
73+
// TODO: Implement getAuthKey() method.
74+
return null;
75+
}
76+
77+
/**
78+
* Validates the given auth key.
79+
*
80+
* This is required if [[User::enableAutoLogin]] is enabled.
81+
* @param string $authKey the given auth key
82+
* @return bool whether the given auth key is valid.
83+
* @see getAuthKey()
84+
*/
85+
public function validateAuthKey($authKey)
86+
{
87+
// TODO: Implement validateAuthKey() method.
88+
return null;
89+
}
90+
}

0 commit comments

Comments
 (0)