ikaras / yii2-oauth2-rest-template

Yii2 Rest APi Template with OAuth2 server
MIT License
95 stars 27 forks source link

Yii::$app->user->identity returns null #30

Open shayanhusaini opened 7 years ago

shayanhusaini commented 7 years ago

Hi @ikaras, I am using yii2-advanced-template but implemented your logic for oauth2 scopes and permissions. I have created all the files like you and everything is working fine but i want to show "You need to login first" instead of "You are not authorized to perform this action" for requests without access token. As per Yii documentation after rest authentication you can grab the user identity from Yii::$app->user->identity but I am getting null even if the correct access token is passed.

ikaras commented 7 years ago

Hi @shayanhusaini , Sorry, but I moved to python 2 years ago and didn't see at this code from that time. I could wrong, but inside the controller in "protected" by oauth2 action you should have access to user's identity.

In your filters you will have access to user's identity if they stays after OAuth2AccessFilter.

Anyway, if you want to change message "You are not allowed to perform this action." to anything else you can do it in /application/api/components/filters/OAuth2AccessFilter.php at 60 line. Hope it will help you.

porot07 commented 3 years ago

Hi @shayanhusaini , Sorry, but I moved to python 2 years ago and didn't see at this code from that time. I could wrong, but inside the controller in "protected" by oauth2 action you should have access to user's identity.

Hello ikaras, can I ask you, why you moved to python?