Ale*_*yra 5 blackberry oauth cordova
我们目前正在研究使用Phonegap的应用程序的最后润色,并且已经遇到了Blackberry端口的一些问题.
到目前为止,我们一直在审查在线提供的内容,但无法找到真正最终的答案.对于Twitter,Facebook或Foursquare来说,制作和oauth身份验证过程的"正确"方式似乎是使用ChildBrowser插件,实例化一个窗口,然后使用它来处理该过程.
正确地说,似乎缺少Blackberry的ChildBrowser插件.到目前为止,我们一直在寻找Github上的几个私有项目,看起来他们构建/使用了这个功能,但我们不确定如何控制创建的窗口.
这些插件中的大多数(或全部?)是指调用本机Blackberry浏览器来处理URL,但是如何管理回调,获取令牌并关闭窗口,因为它是另一个进程.
例如,我们有这个概念代码:
function openWindow() {
if (typeof blackberry !== 'undefined') {
app_id = SOMETHING_HERE;
redirect = 'http://www.facebook.com/connect/login_success.html';
url = 'https://graph.facebook.com/oauth/authorizeclient_id='+app_id+'&redirect_uri='+redirect+'&display=touch&scope=publish_stream';
var args = new blackberry.invoke.BrowserArguments(url);
blackberry.invoke.invoke(blackberry.invoke.APP_BROWSER, args);
}
}
Run Code Online (Sandbox Code Playgroud)
这适用于打开URL,但就是这样.有没有办法在窗口上获取句柄并为事件注入一些监听器?我们的正确方法应该是什么?
谢谢!
我不是 PhoneGap 用户,但我们确实必须处理非常类似的场景 - 本机应用程序调用移动浏览器来提示 oAuth 流程,然后能够处理对 aative 应用程序的回调。
这可以在 BlackBerry 上使用 BrowserContentProviderRegistry API 实现。您可以注册您的应用程序,以便在特定 MIME 类型返回到浏览器时调用。听起来很复杂,但当所有部分都发挥作用时,它就相当简单了。
这是粗略的流程 -
oAuthRedirectorHandler.asp 有这样的简单代码(我们选择了经典 ASP,但这可以用 PHP 或任何语言完成,您也可以忽略下面的 Android 块)-
<html><body>
<h1>Redirect page</h1>
If you are not re-directed, please open the application manually.
<% strUA = Request.ServerVariables("HTTP_USER_AGENT")
if (InStr(strUA, "BlackBerry")) then
Response.Write("Opening appplication on BlackBerry")
Response.ContentType="application/x-MyCustomApp"
elseif (InStr(strUA, "Android")) then
Response.Write("Opening appplication on Android")
Response.Redirect("MyCustomApp://mycompany.com")
end if %>
</body> </html>
Run Code Online (Sandbox Code Playgroud)在您的 BlackBerry 代码中,您需要一个像这样的新 BrowserContentProvider -
final class CustomBrowserProvider extends BrowserContentProvider{
String[] ACCEPT = new String[]{"application/x-MyCustomApp};
String appName;
CustomBrowserProvider(String appName){
this.appName = ApplicationDescriptor.currentApplicationDescriptor().getModuleName();
//cache this appName from the constructor in the invocation code below.
}
public String[] getSupportedMimeTypes() { return ACCEPT;}
public String[] getAccept(RenderingOptions context){return ACCEPT;}
public BrowserContent getBrowserContent( BrowserContentProviderContext context) throws RenderingException {
//this is where the callback happens
//this is happening in a separate process, raise your main app here using the appName that got passed in
//I dont have a sanitized ready to go sample to post here on how to do this, but not too complicated
//as a hint use the ApplicationDescriptor and CodeModuleManager classes
return null;
}
}
Run Code Online (Sandbox Code Playgroud)现在,在您的应用程序初始化中,像这样注册这个新的 BrowserPlugin -
BrowserContentProviderRegistry converterRegistry = BrowserContentProviderRegistry.getInstance();
converterRegistry.register(new CustomBrowserProvider());
Run Code Online (Sandbox Code Playgroud)希望这可以帮助。这对我们来说效果很好。我们遇到的一个缺点是,当用户返回浏览器应用程序时,他们会看到一个空白页面,并且没有好的方法可以在 BB 中关闭该页面。
| 归档时间: |
|
| 查看次数: |
1743 次 |
| 最近记录: |