簡體   English   中英

標頭Rest Api中的身份驗證

[英]Authentication in header Rest Api

我正在使用codeigniter中的 rest api ,並且我想添加api-authentication ,因此,我要在郵遞員的標頭部分發送access_token ,但我想知道如何在.php文件中獲取它。 我只希望嘗試在沒有access_token或錯誤的access_token情況下嘗試api的人不應該獲得api結果。 在我的controller我輸入了以下代碼。 如何在rest api上添加身份驗證?

if ($access_token!= $_POST['access_token']) {
   echo "<p>Hello {$_SERVER['PHP_AUTH_USER']}.</p>";

} else {
    header('WWW-Authenticate: Basic realm="My Realm"');
    header('HTTP/1.0 401 Unauthorized');
    echo 'any text';
}

如果要在codeigniter中創建RESTful服務器,請考慮使用https://github.com/chriskacerguis/codeigniter-restserver庫。

對於在codeigniter中進行API身份驗證的實現,請考慮使用https://github.com/ParitoshVaidya/CodeIgniter-JWT-Sample

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM