Yii2 REST API authentication

前端 未结 1 994
逝去的感伤
逝去的感伤 2021-01-07 13:17

I was looking for tutorials and read yii\'s official tutorial about REST API and authentication, but I just can\'t figure it out how to authenticate user via REST API. How t

1条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2021-01-07 13:45

    I think login process will be more or less same. Only Url structure is different when you use REST API, but what you do in actions is up to you. Any where in you application you can check if user is logged in or not with this code:

    \Yii::$app->user->isGuest
    

    It will return true if user is NOT logged in otherwise false.

    And if you need to restrict access to actions then you can use Access Control Filter or Role Based Access Control

    Again I think Access Control Filter implementation should be same even for REST API.

    0 讨论(0)
提交回复
热议问题