htaccess身份验证其他api方法

时间:2015-06-03 20:17:37

标签: .htaccess rest http authentication http-authentication

我使用CakePHP构建了REST API服务,我需要使用http身份验证来保护我的一些方法。例如,我有类似的方法:

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

我希望保护这个特定路径(/ api / store)以使用http身份验证来调用cron job

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

有可能吗?如果是这样,那怎么样?谢谢!

1 个答案:

答案 0 :(得分:1)

我们解决了这个问题。只要那个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
相关问题