Ken*_*eda 12 php authentication cakephp postman angular
我有一个Angular7在客户端使用的Web应用程序,然后CakePHP在Api
我使用的Web应用程序中将Basic Authentication其替换为Token Authentication所有请求都可以正常工作,但只有一个可以在请求中正常运行,Postman但在浏览器中却很奇怪,因为似乎认证存在问题,但不知道原因。
该请求应返回一个Blob以下载文件,因此我使用FPDIin CakePHP来返回pdf
这是邮递员的要求
邮递员头
Date ?Wed, 15 May 2019 12:02:44 GMT
Server ?Apache/2.4.33 (Win32) OpenSSL/1.0.2n PHP/5.6.35
X-Powered-By ?PHP/5.6.35
Content-Disposition ?inline; filename="doc.pdf"
Cache-Control ?private, max-age=0, must-revalidate
Pragma ?public
Access-Control-Allow-Origin ?*
Keep-Alive ?timeout=5, max=100
Connection ?Keep-Alive
Transfer-Encoding ?chunked
Content-Type ?application/pdf
Run Code Online (Sandbox Code Playgroud)
邮递员的身体
在Chrome上请求
使用基本身份验证的工作请求
使用FireFox
通话要求
getWorkListPdf(id: number, cem_id?: number) {
let uri = `${this.workSessionsUrl}workList/${id}`;
let params = new HttpParams();
if (cem_id) {
params = params.set('cemetery_id', cem_id.toString());
}
const Auth = localStorage.getItem("AuthenticationToken");
let header = new HttpHeaders();
header = header.append("AuthenticationToken", Auth);
return this.dataService.get(uri,{ headers: header, params: params, responseType: 'arraybuffer' })
.pipe(
map(res => {
return res;
}
)
);
}
Run Code Online (Sandbox Code Playgroud)
任何帮助深表感谢!
问题是Api无法识别包含身份验证所需的标头信息的请求,我在其中添加了Authentication数组AppController以允许同时使用它们,Basic Auth并且Token Auth在接收json请求时,此请求对所有请求都可以正常工作,但我对此请求除外(下载pdf)试图添加
$this->Auth->authenticate['Token'] = array(
'fields' => array(
),
// 'parameter' => '_token',
'header' => 'AuthenticationToken',
'scope' => array(
'User.permission_api_login' => true
)
);
Run Code Online (Sandbox Code Playgroud)
再次在控制器中,它工作正常!!看来它现在可以识别令牌并返回有效文件!
| 归档时间: |
|
| 查看次数: |
1539 次 |
| 最近记录: |