Phonegap oauth2 redirect issue

自闭症网瘾萝莉.ら 提交于 2019-12-12 02:45:27

问题


tl;dr I am trying to implement oauth in my cordova app (multi-device hybrid app in VS2013) but have problems with getting the tokens back

For my internship project I have made a basic oauth server and added it to an existing project. When the mobile application sends the user to the authentication page he sends along his ID token and a redirect URL.

The authentication works and access and refresh tokens are generated. I only have trouble with sending them back to the app. I localhost both my app and the authentication site and due to that I can't really test some aspects of it I think. I can't use the Hyper-V emulator because he can't link to local hosted websites.

I use the following JS code to extract the url from my cordova app, I do not know if this is a valid url to where a user can be redirected.

http://www.thecodeship.com/web-development/javascript-url-object/

I use this code to send the user to the authentication page.

function goToAuth() {

var test = urlObject();
//Put the url in the demo ID element
appUri = test.protocol + test.host + test.hash + test.pathname + test.search;
var redirecturl = 'http://localhost:50587/Login/IndexMobile?token=gh0BcoTaNUu6fc3GK8jN&redirecturi='+ appUri;

var ref = window.open(redirecturl, '_blank', 'location=yes');

ref.addEventListener('loadstart', function (event) { alert('start: ' + event.url); });
ref.addEventListener('loadstop', function (event) { alert('stop: ' + event.url); });
ref.show();
ref.addEventListener('loaderror', function (event) { alert('error: ' + event.message); });
ref.addEventListener('exit', function (event) { alert(event.type); });}

In asp.net I use this line of code to redirect the user back to the redirectUri provided.

return Redirect(redirectUri);

He gives me an 'not a valid path' error though, but I think that is due to the app being local hosted via Ripple.

Now I know that what needs to happen is that when the user finishes authentication, that page should close and he should go back to the app, and the app needs to be able to access the tokens. I first thought I could do this by redirecting the user with the tokens but I can not test this approach.

I also read a bit about JS callbacks but I am new to this and don't know how to use it on my cordova app.


回答1:


Authentication is falling because the callback uri or redirect uri registered in the server does not match one used by Ripple. In CPT 3.0 and Visual Studio 2015 Preview, Visual Studio selects port ranging from 4400 and 4444 and since port no. is randomly selected between 4400 and 4444, it is difficult to know the port beforehand.

Therefore it is better to use either an emulator or a device for OAuth.



来源:https://stackoverflow.com/questions/27564662/phonegap-oauth2-redirect-issue

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!