【问题标题】:Request alfresco authentication token with ajax POST/GET call (Angular)使用 ajax POST/GET 调用(Angular)请求 alfresco 身份验证令牌
【发布时间】:2017-10-11 14:55:31
【问题描述】:

问题来了,

我尝试使用 js(角度 4)脚本从我的 alfresco 社区服务器获取身份验证令牌。该请求似乎被“CORS header missing”阻止...

登录名/密码没问题,因为我可以直接在我的浏览器中尝试登录 URL,我得到了预期的结果(xml),如下所示:

https://www.my-url.com/alfresco/service/api/login?u=username&pw=password

我得到了这个结果:

现在,我来到我的网络应用程序,我需要从 http 调用中检索这张票,就像这样(使用 angular 4 服务):

getTicket(user: User): Observable<boolean>{
    let headers = new Headers();
    headers.append('Access-Control-Allow-Origin','*');
    return this.http.post('https://www.my-url.com/alfresco/service/api/login',{'u':'username','pw':'password'},{headers:headers}).map(response => {
        console.log('response : '+JSON.stringify(response));
    });
}

我对 u/pw 变量进行了硬编码,我还尝试将它们命名为“用户”和“密码”,我也尝试了 GET 方法,但没有任何变化,我唯一得到的就是 Cors 问题。结果在控制台:

选项 XHR https://www.my-url.com/alfresco/service/api/login [HTTP/1.1 200 OK 39 毫秒]

跨域请求被阻止:同源策略不允许读取 远程资源...原因:CORS 标头 'Access-Control-Allow-Origin' 缺失。

请求数据:

Response Headers : 
Allow: "OPTIONS, GET, POST"
Content-Length: "0"
Date : "Wed, 11 Oct 2017 14:37:45 GMT"
Server: "Apache-Coyote/1.1"

Request Headers : 
Host : "www.my-url.com"
User-Agent : "Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Firefox/45.0"
Accept: "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8"
Accept-Language : "en-US,en;q=0.5"
Accept-Encoding: "gzip, deflate"
Access-Control-Request-Method: "POST"
Access-Control-Request-Headers: "access-control-allow-origin"
Origin: "http://localhost"
Connection: "keep-alive"

我还尝试删除我为请求手动创建的标头,但没有效果...

【问题讨论】:

  • 你无法在户外使用 CORS 吗?
  • 嗨@Sanjay Patel 感谢您的评论。好吧,我猜它已启用,因为我的 http 在浏览器中工作。顺便说一句,我对如何在 alfresco 中启用 cors 进行了多次搜索,但没有发现任何明确/相关的内容......你能帮我解决这个问题吗?
  • 您使用的是哪个版本的 alfresco?
  • 如果您使用的是 alfresco 5.2,请将 enablecors-1.0.jar 放入 modules/platform 文件夹中。 community.alfresco.com/…

标签: javascript ajax authentication cors alfresco


【解决方案1】:

如何在 alfresco V5.2 中启用 CORS?把enablecors-1.0.jar 在模块/平台文件夹中。

【讨论】:

  • 我的 Alfresco 版本是 5.1.0 (r127059-b7) 这不起作用。我仍然有这个“缺少响应的标题”错误......奇怪......
  • 感谢您的帮助,您确实为我指明了正确的方向,我找到了这个:community.alfresco.com/message/… 它解决了我的问题 :)
猜你喜欢
  • 2016-04-04
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2018-11-12
  • 1970-01-01
  • 2019-02-21
  • 2015-02-11
  • 2012-02-29
相关资源
最近更新 更多