离线LinkedIn cordova身份验证坏重定向 [英] Ionic LinkedIn cordova authentication bad redirect

查看:164
本文介绍了离线LinkedIn cordova身份验证坏重定向的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用LinkedIn登入。我设法得到的访问,但分裂的秒,然后重定向到我告诉它的页面,我看到这个错误

I am trying to login using LinkedIn. I manage to get the accesstoken but for a split second before redirecting to the page I tell it to, i see this error


HTTP错误404.0 - 找不到
您正在查找的资源已删除,其名称已更改或暂时不可用。

HTTP Error 404.0 - Not Found The resource you are looking for has been removed, had its name changed, or is temporarily unavailable.

这是链接


http:// localhost:80 / callback?code = ****& state = WQ7IIHGw

http://localhost:80/callback?code=****&state=WQ7IIHGw

while Ionic在我的本地主机:8100,我已将授权重定向URLS设置为 http:// localhost / callback 在链接的开发者页面

while Ionic works on my localhost:8100, I have set the the Authorized rediect URLS to http://localhost/callback in the linked in developer page

此外,
当我设置重定向URL链接到除localhost /错误

Also, when I set the linked in redirect URL to anything but the localhost/call back i get this error


redirect_uri无效。此值必须与API Key注册的网址相匹配。

Invalid redirect_uri. This value must match a URL registered with the API Key.


推荐答案

设置LinkedIn帐户开发人员选项 https://www.linkedin.com/developer/apps/

添加应用程序后,进入其设置:

Setup LinkedIn account developer options: https://www.linkedin.com/developer/apps/
After adding application go to its settings:


  1. 在验证码中,您将获得客户端ID 客户端密码

  2. 在授权重定向网址中,您必须输入: http:// localhost / callback ,因为它将 $ cordovaOauth 使用

  3. 保存/更新帐户设置

  1. In Authentication Keys you will get Client ID and Client Secret
  2. In Authorized Redirect URLs you must put: http://localhost/callback since it will be used by $cordovaOauth
  3. Save/update account settings


b $ b

设置Ionic应用程式:


  1. 安装 cordovaOauth bower install ng-cordova-oauth -S

添加< script src =lib / ng-cordova-oauth / dist / ng-cordova-oauth.js >< / script> index.html 'ngCordovaOauth' apps.js

添加 $ cordovaOauth 到控制器依赖

向控制器添加函数(仅客户机ID 秘密需要被来自LinkedIn dev帐户的数据替换):

Add function to controller (only Client ID and Client Secret need to be replaced by the data from LinkedIn dev account):

  $scope.linkedInLoginIonic = function () {
        var linkedinUriApi = "https://api.linkedin.com/v1/people/~:(email-address,first-name)?format=json&oauth2_access_token=";
        $cordovaOauth.linkedin("Client ID", "Client Secret", ['r_basicprofile', 'r_emailaddress'])
            .then(function (success) {
                    // Here you will get the access_token
                    console.log('Granted access to linkedin');
                    console.log(JSON.stringify(success));
                    // In request below my default header is disabled - otherwise Linkedin API will reject request
                    $http(
                        {method: 'GET',
                            url: linkedinUriApi + success.access_token,
                            headers: {Authorization: undefined}
                        }).then(function (response) {
                        console.log(response);
                    }, function (error) {
                        console.log(error);
                        console.log('Ionic LinkedIn API request after successful login failed');
                    });
                },
                function (error) {
                    console.log(error);
                });
    };


提示:


  • 请求只能通过设备或模拟器完成 - 在Web浏览器中,您将在控制台中看到:


  • 如果您有默认标题,请在请求LinkedIn API时进行禁用(身份验证通过后)

  • 如果请求成功认证失败后检查范围是否匹配所有:


    • API请求:这里我们请求地址第一名(位于 https://api.linkedin.com/v1/people/~:(email-address,first-name ) $ cordovaOauth 部分 在开发者帐户中设置的['r_basicprofile','r_emailaddress']

    • 范围设置

    • 范围(即只有电子邮件)

    • request can be done only through device or emulator - in web browser you will get in console: Cannot authenticate via a web browser
    • if you have default headers then disable it when requesting LinkedIn API (after authentication go well)
    • if request after successful authentication fail check if scopes matches for all:
      • API request: here we ask for address and first-name in https://api.linkedin.com/v1/people/~:(email-address,first-name)?
      • scope set when authenticating, see in example $cordovaOauth part ['r_basicprofile', 'r_emailaddress']
      • scope set in LinkedIn developer account
      • do final API request with minimal scope (i.e. only email)

      这篇关于离线LinkedIn cordova身份验证坏重定向的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆