Nguyen Duy Phong
Nguyen Duy Phong

Reputation: 124

REST API for yii2, the authenticator (HttpBearerAuth) is not working on server

I've just created a project for working with REST API (using yii2 framework).
All issues of REST API is working really cool on localhost. But when bringing the project on server (also the same database is taken by), the authorization is not available. Now I'm using "yii\filters\auth\HttpBearerAuth"

Inside the model "implements IdentityInterface", there's finding-token function "findIdentityByAccessToken" that's so simple, the "validateAuthKey" function is returning always true; see below:

public static function findIdentityByAccessToken($token, $type = null){  
    return static::findOne(["token" => $token]);  
}

public function validateAuthKey($token)    
{ 
    return true;  
}  

See any pictures: https://www.flickr.com/photos/40158620@N03/20701523349/in/dateposted-public/ Anyone can have some experience on this problem, can you tell me how to solve it? Thanks for your kindness.

Upvotes: 3

Views: 3969

Answers (2)

Mohamed Khalil
Mohamed Khalil

Reputation: 3126

In my case the Problem was that the server removes Authorization Header I needed to add this to .htaccess

 SetEnvIf Authorization "(.*)" HTTP_AUTHORIZATION=$1

Upvotes: 6

Tahiaji
Tahiaji

Reputation: 430

HttpBearerAuth used $user->loginByAccessToken to authorize see

validateAuthKey used by "loginByCookie"(and it seems that in this case not used)

Try to use QueryParamAuth for test purposes (it's easier to test)

Upvotes: 0

Related Questions