首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Azure CORS问题上托管的Angular 4前端

Azure CORS问题上托管的Angular 4前端
EN

Stack Overflow用户
提问于 2017-09-25 23:36:21
回答 1查看 591关注 0票数 0

我正在构建一个使用Angular 4的web应用程序,它试图发布到VSTS Rest API。我显然不拥有这个服务,我试图在Azure中运行,而不是在本地运行(我知道我可以在本地测试中禁用chrome中的CORS )。

代码语言:javascript
复制
Failed to load 
https://app.vssps.visualstudio.com/oauth2/tokenRemovedtoStackOverflow 
Response to preflight request doesn't pass access control check: No 'Access-
Control-Allow-Origin' header is present on the requested resource. Origin 
'https://blah.azurewebsites.net' is therefore not allowed access. The 
response had HTTP status code 400.

Call基本上是:

代码语言:javascript
复制
private _appID = blah;
private _tokenRequest = 'client_assertion_type=urn:ietf:params:oauth:client-assertion-type:jwt-bearer&client_assertion={0}&grant_type=urn:ietf:params:oauth:grant-type:jwt-bearer&assertion={1}&redirect_uri={2}';
  private _returnURI = 'https://blah.azurewebsites.net/';
  private headers = new Headers(
    {
      'Access-Control-Allow-Origin': '*',
      'Access-Control-Allow-Headers': 'Content-type',
      'Content-Type': 'application/x-www-form-urlencoded',
    });

  constructor(private http: Http) { }

  getAccessToken(code: string): Observable<IToken> {
    const _url = 'https://app.vssps.visualstudio.com/oauth2/' + code;
        const body = 'client_assertion_type=urn:ietf:params:oauth:client-assertion-type:jwt-bearer&client_assertion=' +
      this._appID +
      '&grant_type=urn:ietf:params:oauth:grant-type:jwt-bearer&assertion=' +
      code + '&redirect_uri=' +
      this._returnURI;
    const options = new RequestOptions();
    options.headers = this.headers;

      return this.http
        .post(_url, body, options)
        .map((response: Response) => <IToken[]> response.json())
        .do(data => console.log('All: ' +  JSON.stringify(data)))
        .catch(this.handleError);

目前我没有服务器/api(AKA,我的源代码中唯一的东西是angular),它只是在Azure web应用程序提供的任何服务器上运行。

在azure中添加nodejs服务器是绕过CORS的唯一选择吗?

EN

回答 1

Stack Overflow用户

发布于 2017-09-25 23:40:31

Access-Control-Allow-OriginAccess-Control-Allow-Headers响应报头。他们对你的请求没有位置。

添加自定义标头是生成400错误的印前检查选项请求的触发器之一。

删除它们应该会使请求成为一个简单的请求,并且可能被服务所允许。

如果失败:是的,您需要更改主机,以便它授予您权限。

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/46409036

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档