Skip to content

Instantly share code, notes, and snippets.

@cs-sonar
Created May 2, 2014 13:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cs-sonar/ed656b7397cb4dcc22c3 to your computer and use it in GitHub Desktop.
Save cs-sonar/ed656b7397cb4dcc22c3 to your computer and use it in GitHub Desktop.
fuelphp_rest_auth

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

restコントローラーではbefore内で、全体のログインチェックを行う事が出来ない。

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;
	}
}

fuel/config/rest.php (copy from fuel/core/config/rest.php)

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

	'auth' => 'auth',

結果

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

ログインしていない場合

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

ログインしている場合

{"content":{"key":"hoge"}}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment