【问题标题】:Unable to authorize with LinkedIn JS SDK on iOS Safari from non-https url无法通过非 https url 在 iOS Safari 上使用 LinkedIn JS SDK 进行授权
【发布时间】:2015-08-17 20:48:00
【问题描述】:

LinkedIn JS SDK 似乎存在错误。您可以使用他们在文档的“入门”部分中提供的代码进行复制。

<!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>

如果您将此代码放在非 https 网站上并在 iOS Safari 上点击该 URL,则单击“使用 LinkedIn 登录”按钮将启动授权,但不会触发“auth”回调。相反,您会在控制台中收到 CORS 错误:

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

所有其他环境似乎都可以正常工作(例如 Chrome、FF、IE、桌面 Safari、Android 浏览器等)。如果我在 Chrome 的开发工具中将用户代理设置为 iOS 设备,我也能够重现该问题,这让我认为 JS SDK 正在执行用户代理嗅探。

有解决方法吗? LinkedIn 开发团队是否意识到这个问题?我错过了星期一的细节吗?

PS 这可能是相关的:Sign in with Linkedin doesn't trigger callback on iOS Safari when using the JS API

【问题讨论】:

    标签: mobile-safari linkedin linkedin-jsapi


    【解决方案1】:

    根据 LinkedIn 的 Getting Started with the JavaScript SDK 页面,LinkedIn JavaScript SDK 不支持 iOS 5+。

    注意:JavaScript SDK 与 iOS 5+ 不兼容。

    【讨论】:

    • 好的,那应该是什么替代方案?
    • 我将其解读为“与 v5 之后的任何 iOS 版本不兼容”。这很难理解......
    【解决方案2】:

    @degrassesagan 我认为您需要执行以下操作:

    function onLinkedInLoad() {
      IN.Event.on(IN,"auth",getProfileData);
      IN.Event.on(IN,"success",onSuccess);
      IN.Event.on(IN,"error",onError);
    }
    

    我还发现了一个与 LinkedIn JS SDK 相关的附带问题。我使用的是移动版 Safari 10.3.3,虽然登录业务逻辑正确执行,但 URL 流却没有。 成功登录后,页面会转到 LinkedIn 的“页面未找到”页面,而不是关闭当前浏览器选项卡,以显示下面的所有者页面?

    我不确定这是否与原始问题有关,但如果有人能阐明这个问题,我将不胜感激。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-08-03
      • 2013-06-12
      相关资源
      最近更新 更多