https://www.linkedin.com/oauth/v2/authorization响应显然不包含
Access-Control-Allow-Origin响应标头,并且由于不包含响应标头,因此您的浏览器会阻止您的前端Javascript代码访问响应。
您无法对自己的前端Javascript代码进行任何更改,也不会对后端配置设置进行任何更改,这些设置将允许您的前端Javascript代码以直接尝试的方式发出请求
https://www.linkedin.com/oauth/v2/authorization并成功返回响应。
https://developer.mozilla.org/zh-
CN/docs/Web/HTTP/Access_control_CORS进行了更详细的说明,但要点是,对于CORS,发送请求的服务器必须配置为发送
Access-Control-Allow-Origin响应标头,也不是您自己的后端服务器。
2019-05-30更新
目前的情况似乎是,当需要进行linkedIn授权时,您将必须从后端代码中发起请求。您无法从前端代码中完成此 *** 作,因为linkedIn不再为它提供任何支持。
linkedIn之前确实提供了一些从前端代码处理它的支持。但是记录它的页面https://developer.linkedin.com/docs/getting-
started-js-sdk,现在有了此通知:
当前不支持Javascript SDK
而且https://engineering.linkedin.com/blog/2018/12/developer-program-
updates具有以下内容:
我们的Javascript和移动软件开发套件(SDK)将停止工作。开发人员将需要直接从其应用迁移到使用OAuth 2.0。
因此,此答案的其余部分(从2017年6月13日开始,即大约2年前,在此更新之时)现在已过时。但是为了保持历史记录完整,下面将其保留下来。
2017-06-13详细信息,现在已废弃
无论如何,https://developer.linkedin.com/docs/getting-started-js-
sdk都有官方文档,解释了如何为用户跨域请求授权,这似乎就是这样:
<script type="text/javascript" src="//platform.linkedin.com/in.js"> api_key: [API_KEY] onLoad: [ONLOAD] authorize: [AUTHORIZE] lang: [LANG_LOCALE]IN.User.authorize(callbackFunction, callbackScope);</script>
并且https://developer.linkedin.com/docs/signin-with-
linkedin还有其他文档,该文档具有另一个身份验证流程:
<script type="in/Login"></script> <!-- Create the "Sign In with linkedIn" button--><!-- Handle async authentication & retrieve basic member data --><script type="text/javascript"> // Setup an event listener to make an API call once auth is complete function onlinkedInLoad() { IN.Event.on(IN, "auth", getProfileData); } // Handle the successful return from the API call function onSuccess(data) { console.log(data); } // Handle an error response from the API call function onError(error) { console.log(error); } // Use the API call wrapper to request the member's basic profile data function getProfileData() { IN.API.Raw("/people/~").result(onSuccess).error(onError); }</script>
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)