user-management icon indicating copy to clipboard operation
user-management copied to clipboard

RESTFUL

Open oscarsantook opened this issue 6 years ago • 4 comments

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?

oscarsantook avatar Mar 31 '18 12:03 oscarsantook

me too! please help us!

rizrob66 avatar Oct 20 '21 15:10 rizrob66

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

colesnic89 avatar Oct 21 '21 16:10 colesnic89

@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?

rizrob66 avatar Oct 22 '21 07:10 rizrob66

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

colesnic89 avatar Oct 23 '21 18:10 colesnic89