Help us understand the problem. What is going on with this article?

fuelphpのrestコントローラでログインチェックを行う

More than 5 years have passed since last update.

rest controllerでのログインチェック

restコントローラーでログインチェックを行う方法

controller

以下のようなrestの例があった場合。

fuel/app/classes/api.php
class Controller_Api extends \Fuel\Core\Controller_Rest
{
    public function get_create()
    {
        $name = Input::get('key');
        $this->data['content'] = array('key' => $name);
        return $this->response($this->data, 200);
    }

    public function auth()
    {
        if(Auth::check())
        {
            return true;
        }
        return false;
    }
}

config

config内でauthにrestコントローラーで認証を行わせるメソッドを記述する.

fuel/config/rest.php (fuel/core/config/rest.php)
    'auth' => 'auth',

結果

http://example.com/api/create.json?key=hoge

ログインしていない場合

{"status":0,"error":"Not Authorized"}

ログインしている場合

{"content":{"key":"hoge"}}

cs_sonar
Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
Comments
No comments
Sign up for free and join this conversation.
If you already have a Qiita account
Why do not you register as a user and use Qiita more conveniently?
You need to log in to use this function. Qiita can be used more conveniently after logging in.
You seem to be reading articles frequently this month. Qiita can be used more conveniently after logging in.
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
ユーザーは見つかりませんでした