Tuesday, 16 April 2019

SignIn With LinkedIn Authorize Promise Undefined

I recently began having issues with my Signin With Linkedin functionality. I get the following error:

Uncaught TypeError: Cannot read property 'then' of undefined at Object.authorize (in.js:18)

I do have my redirect urls correctly defined in my apps' OAuth 2.0 settings.

My LinkedIn App has the following permissions listed in it:

  • r_emailaddress
  • w_share
  • r_basicprofile
  • r_liteprofile
  • rw_company_admin
  • w_member_social

Here is my code:

<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();
    });

Here is the relevant function from LinkedIn's in.js:

authorize: function(t, n) {
    return t = t ? t.bind(n || window) : function() {}
    ,
    e().credentials.isAuthenticated ? (t(),
    !0) : (e().authorize().then(t),
    !1)
},

And it is the e().authorize() on line 5 that is undefined.

I'm not sure if this issue is related to LinkedIn's API upgrade to 2.0 or if there is some synchronicity issue with the promise returned as a part of the authorize function. Really as a loss as to why this started and how to fix it.



from SignIn With LinkedIn Authorize Promise Undefined

2 comments: