离线LinkedIn cordova身份验证坏重定向 [英] Ionic LinkedIn cordova authentication bad redirect
问题描述
我想使用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:
- 在验证码中,您将获得
客户端ID
和客户端密码
- 在授权重定向网址中,您必须输入: http:// localhost / callback ,因为它将
$ cordovaOauth
使用 - 保存/更新帐户设置
- In Authentication Keys you will get
Client ID
andClient Secret
- In Authorized Redirect URLs you must put: http://localhost/callback since it will be used by
$cordovaOauth
- Save/update account settings
b $ b
设置Ionic应用程式:
-
安装 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
andfirst-name
inhttps://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屋!
- API request: here we ask for
- API请求:这里我们请求