yii2-rest-api | Yii 2 REST API Project Template | Web Framework library
kandi X-RAY | yii2-rest-api Summary
kandi X-RAY | yii2-rest-api Summary
Yii 2 REST API Project Template
Support
Quality
Security
License
Reuse
Top functions reviewed by kandi - BETA
- Add authentication handlers .
- Create new user
- Before sending event
- Set cookie key .
- Convert enum value to enum value
- Overrides the default fields
- Create safe table
- Error action .
- Login action .
- Bootstrap application events .
yii2-rest-api Key Features
yii2-rest-api Examples and Code Snippets
# create a user via: POST /v1/join
curl -X POST -H "Content-Type: application/json" -d '{"username":"demo","email":"demo@email.com","password":"pass123"}' http://localhost:8000/v1/join
# should return like: {"code":0,"data":{"username":"demo","email"
composer create-project --prefer-dist forecho/yii2-rest-api
cd
cp .env.example .env
php yii generate/key # optional
chmod 777 -R runtime/
http://localhost//web/
git clone xxxx
cd
cp .env.example .env
chmod 777 -R runtime/
http://localhost//web/
Community Discussions
Trending Discussions on yii2-rest-api
QUESTION
I am implementing Rest API in yii2. I want to authenticate the user using access token. I have referred various SO answers as follows
But I m not clear, which authentication method I should use and how I will get user identity.
I have created findIdentityByAccessToken()
method in my user identity class as suggested in Yii2 Rest guide .
Below is the behaviour
implemented in my controller
ANSWER
Answered 2017-Jan-05 at 15:23Simple answer there's more than one possibility to implement this behavior.
Both HttpBearerAuth
and HttpBasicAuth
can use the findIdentityByAccessToken()
methode when configured correctly. the behavior you should use depends on the way you want users to authenticate themselves.
if you read the documentation of HttpBasisAuth
HttpBasicAuth you'll see
The default implementation of HttpBasicAuth uses the loginByAccessToken() method of the user application component and only passes the user name. This implementation is used for authenticating API clients.
loginByAccesToken
will invoke the findIdentityByAccesToken
methode
You can manipulate this behavior by defining a closure in the auth attribute see auth attribute.
HttpBeareAuth
almost does the same. it also implements the loginByAccessToken
So what make the two different from each other? simple the location where the get the data from. where HttpBasicAuth
expects that client has set the basic header example header('Authorization: Basic '. base64_encode("user:password"));
(PHP has build in support for this see: http://php.net/manual/en/features.http-auth.php)
the HttpBearerAuth
expects that the header is defined as the following header('Authorization: Bearer '. $token);
So the solution you should use depends on the way you want users/clients to authenticate themselves. you could also use the QueryParamAuth
which gives the users the possibility to authenticate themselves whit a GET param see queryparamauth
And if you want to use a custom header let's say X-API-Token create your own custom class that implements the AuthMethod
interface see AuthMethod
Hope this helps
Community Discussions, Code Snippets contain sources that include Stack Exchange Network
Vulnerabilities
No vulnerabilities reported
Install yii2-rest-api
Accessing Use this template Create a new repository from yii2-rest-api.
Update your vendor packages. Run the installation triggers (creating cookie validation code).
Minimum required Docker engine version 17.04 for development (see Performance tuning for volume mounts)
The default configuration uses a host-volume in your home directory .docker-composer for composer caches
Support
Reuse Trending Solutions
Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from over 650 million Knowledge Items
Find more librariesStay Updated
Subscribe to our newsletter for trending solutions and developer bootcamps
Share this Page