Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/.htaccess/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
.htaccess htaccess认证restapi方法_.htaccess_Rest_Http_Authentication_Http Authentication - Fatal编程技术网

.htaccess htaccess认证restapi方法

.htaccess htaccess认证restapi方法,.htaccess,rest,http,authentication,http-authentication,.htaccess,Rest,Http,Authentication,Http Authentication,我使用CakePHP构建了RESTAPI服务,我需要使用http身份验证来保护我的一些方法。例如,我有如下方法: POST /api/store { name: "John", surname: "Johnny", ... } 我想保护这个特定的路径(/api/store),通过http身份验证来调用cron作业 http://username:password@server.com/api/store 这样的事情可能吗?如果是,那怎么办?谢谢大家! 我们解决了这个问题。只

我使用CakePHP构建了RESTAPI服务,我需要使用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