webvimark / user-management

153 stars 163 forks source link

RESTFUL #190

Open oscarsantook opened 6 years ago

oscarsantook commented 6 years ago

Hi I configure like Chapter 6. RESTful Web Services of Yii2 Application Development Cookbook Third Edition book, and work fine.

But when I changed tu user-managment I recive:

"name": "Unauthorized", "message": "Your request was made with invalid credentials.", "code": 0, "status": 401, "type": "yii\web\UnauthorizedHttpException"

If I configure at database level username = auth_key work OK but no validate the password.

Can you helpme?

rizrob66 commented 2 years ago

me too! please help us!

colesnic89 commented 2 years ago

@rizrob66 I think you need to use HttpBearerAuth instead default FormLogin authentication

rizrob66 commented 2 years ago

@colesnic89 Thanks for your tips I did it in my Controller: public function behaviors() { $behaviors = parent::behaviors(); //$behaviors['authenticator']['only'] = ['create', 'update', 'delete']; $behaviors['authenticator']['authMethods'] = [ HttpBearerAuth::class, ]; return $behaviors; } but the answer is always "name": "Unauthorized", If I remove comment from $behaviors['authenticator']['only'] = ['create', 'update', 'delete']; index works fine. I did the tests with Postman Bearer Authentication usesing the token in the auth_key. Is it correct?

colesnic89 commented 2 years ago

@rizrob66 It is hard to understand what happened. I always use XDebug in cases like this.