Search code examples
mobile-safarilinkedin-apilinkedin-jsapi

Unable to authorize with LinkedIn JS SDK on iOS Safari from non-https url


There seems to be a bug with the LinkedIn JS SDK. You're able to reproduce with the code they supply in the "Getting Started" section of the docs.

<!DOCTYPE html>
<html>
<head>
    <title>LinkedIn test</title>

    <script>
        // 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>
    <script type="text/javascript" src="//platform.linkedin.com/in.js">
        api_key: [API_KEY]
        onLoad: onLinkedInLoad
    </script>

</head>
<body>

<script type="in/Login"></script>

</body>
</html>

If you put this code on a non-https site and hit that URL on iOS Safari, clicking the "sign in with LinkedIn" button will initiate authorization, but the 'auth' callback will never fire. Instead, you'll get a CORS error in the console:

"Uncaught SecurityError: Blocked a frame with origin "https://platform.linkedin.com" from accessing a frame with origin ..."

All other environments seem to work fine (e.g. Chrome, FF, IE, Desktop Safari, Android browsers, etc.). I'm also able to reproduce the issue if I set the user agent to an iOS device in Chrome's dev tools, which makes me think the JS SDK is doing user-agent sniffing.

Is there a workaround? Is the LinkedIn dev team aware of this issue? Did I miss a Monday detail?

PS This is probably related: Sign in with Linkedin doesn't trigger callback on iOS Safari when using the JS API


Solution

  • According to LinkedIn's Getting Started with the JavaScript SDK page, the LinkedIn JavaScript SDK doesn't support iOS 5+.

    Note: The JavaScript SDK is not compatible with iOS 5+.