我最近开始遇到我的 Signin With Linkedin 功能的问题。我收到以下错误:
Uncaught TypeError: Cannot read property 'then' of undefined at Object.authorize (in.js:18)
我确实在我的应用程序的 OAuth 2.0 设置中正确定义了我的重定向 URL。
我的 LinkedIn 应用程序中列出了以下权限:
- r_emailaddress
- w_share
- r_basicprofile
- r_liteprofile
- rw_company_admin
- w_member_social
这是我的代码:
<script type="application/javascript">
//This will be re-defined where it is needed
var linkedInAPILoaded = function(){};
</script>
<script type="text/javascript" src="https://platform.linkedin.com/in.js">
api_key: ${apiKey}
authorize: true
onLoad: linkedInAPILoaded
lang: en_US
</script>
<form name="li_signin" class="li_signin" action="<c:url value='/signin/linkedin'/>" method="post">
<input type="hidden" name="${_csrf.parameterName}" value="${_csrf.token}"/>
<a id="linkedInIcon" href="javascript:;" aria-label="<spring:message code="oa.social.linkedin.login"/>">
<i class="glyphicon glyphicon-refresh gly-spin hidden"></i>
<img src="<c:url value='/images/In-2C-48px-R.png'/>" alt="<spring:message code='oa.social.linkedin.signin.link' />" />
</a>
</form>
<script type="text/javascript">
var linkedInIcon = $('#linkedInIcon');
function callbackFunction() {
$('#profileOverlay').addClass('hidden');
$('#loadingOverlay').removeClass('hidden');
linkedInIcon.blur();
linkedInIcon.find('.gly-spin').removeClass('hidden');
linkedInIcon.find('img').addClass('hidden');
linkedInIcon.closest('form').submit();
}
linkedInIcon.on('click', function() {
IN.User.authorize(callbackFunction, window);
callbackFunction();
});
以下是 LinkedIn 的 in.js 中的相关函数:
authorize: function(t, n) {
return t = t ? t.bind(n || window) : function() {}
,
e().credentials.isAuthenticated ? (t(),
!0) : (e().authorize().then(t),
!1)
},
第 5 行的 e().authorize() 是未定义的。
我不确定这个问题是否与 LinkedIn 的 API 升级到 2.0 有关,或者作为授权函数的一部分返回的承诺是否存在一些同步问题。对于为什么会开始以及如何解决它,真的是一种损失。