01-12-2013 01:03 PM
Hi there,
I'm using oauth to access Dropbox from a C++/Cascades app which invokes the browser to authenticate in Dropbox and then uses the url callback mechanism to httpserver/listener which then displays message in the browser to say success and ask the user to return to the app .. ideally I'd like the message displayed in the browser to have a button which when clicked invokes the app for them and I've managed to put in what I think is the required html content which works partly but it doesn't respond to the blackberry.invoke.invoke call itself ..
I suspect that it's because it needs the webworks.js which I assume has the blackberry.invoke.invoke code in it and I've included a line from a webworks example to load this but either that's wrong or I somehow need to include that library in the C++/Cascades project maybe?
here's the html I'm writing into the browser, can anyone help to get this to work? Let me know if more detail needed ..
p.s. the button is displayed and when I click on it it does call the invokeApp() function as I see the first debug alert message displayed but nothing after that
QByteArray content;
content.append("<HTML><h1>Account linked, go ahead back to the app and check the status!</h1>");
content.append("<script src=\"local:///chrome/webworks.js\" type=\"text/javascript\"></script>");
content.append("<script type=\"text/javascript\">");
content.append("function onInvokeSuccess() {");
content.append(" alert(\"Invocation successful!\");");
content.append("}");
content.append("function onInvokeError(error) {");
content.append(" alert(\"Invocation failed, error: \" + error);");
content.append("}");
content.append("function invokeApp() {");
content.append(" alert(\"debug in invokeApp 1 \");");
content.append(" blackberry.invoke.invoke({");
content.append(" target: \"com.example.MyApp.view\",");
content.append(" action: \"bb.action.OPEN\",");
content.append(" type: \"text/plain\",");
content.append(" data: \"Hello, I invoked you\"");
content.append(" }, onInvokeSuccess, onInvokeError);");
content.append(" alert(\"debug in invokeApp 2 \");");
content.append("}");
content.append("</script>");
content.append("<input id=\"clickMe\" type=\"button\" value=\"clickme\" onclick=\"invokeApp();\" />");
content.append("</HTML>");
reply.append("HTTP/1.0 200 OK \r\n");
reply.append("Content-Type: text/html; charset=\"utf-8\"\r\n");
reply.append(QString("Content-Length: %1\r\n").arg(content.size()));
reply.append("\r\n");
reply.append(content);
socket->write(reply);
Thanks,
Derek
01-12-2013 02:10 PM
Of course that won't work.
Allowing Invoke calls from the browser would be a huge security breach. Any website could embed javascript do do funky stuff on your device...
01-13-2013 12:44 PM
thanks for response .. I appreciate the security problem of allowing invoke calls from external site but I guess I was hoping that having the url that generates the script being from http://localhost .. would've allowed more as it's then known to be coming from localhost
As it happens though your point got me thinking and I've now switched from invoking the browser to do the authorise portion of the oauth process and simply loaded a QML page with a webview in it within the app itself and hence it's actually much cleaner and neater, doesn't require an http server thread etc. and so is much better approach in general!
Best regards,
Derek