Yii Framework Forum: REST API Autenthication with QueryParamAuth - Yii Framework Forum

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

REST API Autenthication with QueryParamAuth

#1 User is offline   tomorrowknight 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 2
  • Joined: 07-May 17

Posted 03 July 2017 - 04:26 AM

Hi all,

I want to my Android application to receive data using REST API.

Currently,I can call the REST API just fine when I am logged in on my web browser but once I am logged off,a blank json array is returned.

How do I authenticate the user with a token in the URL using QueryParamAuth so that I can receive data from any device.
0

#2 User is offline   itma 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 117
  • Joined: 16-September 13

Posted 04 July 2017 - 03:38 AM

View Posttomorrowknight, on 03 July 2017 - 04:26 AM, said:

How do I authenticate the user with a token in the URL using QueryParamAuth so that I can receive data from any device.


Try the below:

class ApiController extends Controller
{    
    public function beforeAction($action) {
        // Do it here if you want auth a user for each action
    }

    public function actionAuth($token)
    {
        $user = User::find()->where('token = :token', [':token'=> $token])->one();
        if (!$user) {throw new Exception('403')}
    }
}

A full stack developer for hire (andrew@itma.pl)
https://twitter.com/Andrew_Bernat
0

#3 User is offline   itma 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 117
  • Joined: 16-September 13

Posted 04 July 2017 - 05:53 AM

Sorry, not enaugh green tea... I didn't notice that you want to use QueryParamAuth. Take a look at this https://github.com/s...book/issues/165
A full stack developer for hire (andrew@itma.pl)
https://twitter.com/Andrew_Bernat
0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users