douciping4283 2013-02-11 19:50
浏览 66
已采纳

使用基本的http身份验证对无胖框架进行身份验证,如何?

I have two one question about the Fat Free Framework.

First of all, how can i use multiple parameters(tokens in fat free framework) in a GET request? Or, is there only 1 token possible per REST GET request, and should one handle additional arguments as a regular GET request, for example:

domain/rest/somedata/5231?param1=value1&param2=value2

where the ?param1=value1&param2=value2 should be 'manually' parsed, not by a framework?

Is it at all possible to build a RESTful API with Fat Free Framework and also have some area's or routes needing authentication? if so, how?

I just stumbled upon this related question: REST API Best practices: Where to put parameters?

[edit]: i've found out that it is indeed possible to have authentication with fat free framework using several methods. However, they seem not very well documented (at least not on their github wiki).

[edit2] Since it's only very basic authentication, for now i'm using this:

function beforeRoute($f3,$params) {
    $url = $params[0];
    $parsed_key = parse_str(parse_url($url, PHP_URL_QUERY));

    if (isset($apikey)){
        // check if apikey is in database
        $authenticated = false;
        foreach(R::find('apikey') as $key_bean) {
            if($key_bean->key == $apikey) {
                $authenticated = true;
                break;
            }
        }
        if($authenticated == false) $f3->error(403);
    } else {
        $f3->error(403);
    }
}

I'm looking for documentation on the basic http authentication method!

  • 写回答

2条回答 默认 最新

  • doujiyun0041 2013-02-14 09:30
    关注

    The auth class always authenticates you against a mapper. Feel free to use F3's Jig, Mongo or SQL.

    $db = new DB\SQL('mysql:host=localhost;dbname=mydb', 'dbuser', '1234');
    $mapper = new DB\SQL\Mapper($db, 'users');    
    $auth = new Auth($mapper, array('id'=>'username','pw'=>'password'));
    
    if($auth->basic())
        return true;
    

    password and username are field names in the database. id and pw are internal used by the auth class. I recommend checking the auth class code and the unit tests in the dev branch on Github.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥50 汇编语言除法溢出问题
  • ¥65 C++实现删除N个数据列表共有的元素
  • ¥15 Visual Studio问题
  • ¥15 state显示变量是字符串形式,但是仍然红色,无法引用,并显示类型不匹配
  • ¥20 求一个html代码,有偿
  • ¥100 关于使用MATLAB中copularnd函数的问题
  • ¥20 在虚拟机的pycharm上
  • ¥15 jupyterthemes 设置完毕后没有效果
  • ¥15 matlab图像高斯低通滤波
  • ¥15 针对曲面部件的制孔路径规划,大家有什么思路吗