【问题标题】:Error requesting from angular to LinkedIn OAuth API从角度请求 LinkedIn OAuth API 时出错
【发布时间】:2020-05-26 12:40:39
【问题描述】:

我正在尝试在我的 Angular 应用程序中实现 LinkedIn OAuth 授权 API。我向 Linkedin 授权 API 发出了一个简单的 GET 请求。但它被 CORS 政策阻止了。我在标题中添加了“Access-Control-Allow-Origin:*”,但我仍然遇到同样的问题。请检查以下代码、屏幕截图和帮助解决问题。

getAuthorization() {
const httpParams = new HttpParams().append('response_type', 'code')
  .append('client_id', 'xxxxxxxxxxxxxxx')
  .append('redirect_uri', 'http://localhost:4200/home')
  .append('scope', 'r_liteprofile r_emailaddress w_member_social');

const httpHeaders = new HttpHeaders()
  .set('Access-Control-Allow-Origin', '*')
  .set('Content-Type', 'application/x-www-form-urlencoded');

this.httpClient.get('https://www.linkedin.com/oauth/v2/authorization', { headers: httpHeaders, params: httpParams })
  .subscribe(data => {
    this.accessToken = data;
  });

}

【问题讨论】:

    标签: angular oauth-2.0 angular8 linkedin-api


    【解决方案1】:

    Access-Control-Allow Origin 由 bakckend 设置,在您的情况下是linkedin。您必须已经为该客户 ID 注册了linkedin 的应用程序。所以我的猜测是你将无法从 localhost 访问该 api。您需要在已为该客户端 ID 向linkedin 注册的域上检查它。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2019-09-27
      • 2018-12-27
      • 2018-10-16
      • 2017-02-13
      • 1970-01-01
      • 1970-01-01
      • 2011-09-18
      相关资源
      最近更新 更多