簡體   English   中英

htaccess身份驗證rest api方法

[英]htaccess authentication rest api methods

我有使用CakePHP構建的REST API服務,我需要使用http身份驗證來保護某些方法。 例如,我有類似的方法:

POST /api/store
{
   name: "John",
   surname: "Johnny",
   ...
}

我想保護此特定路徑(/ api / store)以通過http身份驗證來調用cron作業

http://username:password@server.com/api/store

這樣有可能嗎? 如果是這樣,那又如何? 謝謝!

我們解決了這個問題。 只要該url / api / store不是物理路徑,我們就需要使用不同的方法來感謝使用基本的http auth安全文件夾。

SetEnvIf Request_URI ^/api/store protected_method=true
# we need to match url with regex and set it to "protected_method" variable    

# Commom auth
AuthUserFile /absolute/path/to/directory/of/api
AuthName "This method is pwd protected"
AuthType Basic

Order Deny,Allow
Deny from all
Satisfy any

Require valid-user
#check if requested url is one of protected_method
Allow from env=!protected_method

暫無
暫無

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

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