tl; dr 我正在尝试在我的cordova应用程序中实现oauth(VS2013中的多设备混合应用程序),但是在获取令牌时遇到问题
对于我的实习项目,我已经制作了一个基本的oauth服务器并将其添加到现有项目中。当移动应用程序将用户发送到身份验证页面时,他会发送其ID令牌和重定向URL。
身份验证正常工作,并生成访问和刷新令牌。我只是将它们发送回应用程序时遇到了麻烦。我localhost我的应用程序和身份验证站点,因为我不能真正测试它的一些方面我认为。我无法使用Hyper-V模拟器,因为他无法链接到本地托管网站。
我使用以下JS代码从我的cordova app中提取url,我不知道这是否是可以重定向用户的有效URL。
http://www.thecodeship.com/web-development/javascript-url-object/
我使用此代码将用户发送到身份验证页面。
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); });}
在asp.net中,我使用这行代码将用户重定向回所提供的redirectUri。
return Redirect(redirectUri);
他给了我一个'不是一个有效的路径'的错误,但我认为这是因为该应用程序是通过Ripple本地托管的。
现在我知道需要发生的事情是,当用户完成身份验证时,该页面应该关闭,他应该返回应用程序,并且应用程序需要能够访问令牌。我首先想到我可以通过使用令牌重定向用户来做到这一点,但我无法测试这种方法。
我还阅读了一些关于JS回调的内容,但我是新手,并且不知道如何在我的cordova应用程序中使用它。
答案 0 :(得分:0)
身份验证正在下降,因为服务器中注册的回调uri或重定向uri与Ripple使用的不匹配。在CPT 3.0和Visual Studio 2015 Preview中,Visual Studio选择的端口范围为4400和4444,并且端口号为。在4400和4444之间随机选择,事先很难知道这个端口。
因此,最好使用模拟器或OAuth设备。