I'm writing an Ubuntu Touch application in QML. I'd like to integrate with Trello. There are two ways to log into Trello in the API, one of which is OAuth, which I plan on using. What is the best way to do this from QML? I'd prefer not to use a C++ backend, but I am willing to do so if that is the only way.

So I know your app now integrates with Trello. Care to answer your own question?
–
andrewsomethingMar 2 '14 at 16:08

@andrewsomething There are two ways, one is to use OAuth and the other involves opening an external URL and having the user copy back a token. I'm using the second option, without using OAuth. If you'd find a detailed explanation useful even though I'm not using OAuth, I can do a full answer.
–
iBelieveMar 2 '14 at 18:59

2 Answers
2

You could create an account plugin for Trello, so that a Trello account could be created from the "Online Account" panel in the System Settings. The you could use the Ubuntu.OnlineAccounts QML module to login, like this:

This code will get you the OAuth token. In order to create the account in the first place, you need to create the following files:

/usr/share/accounts/providers/trello.provider

/usr/share/accounts/services/trello-board.service

/usr/share/accounts/qml-plugins/trello/Main.qml

Given that Trello uses OAuth 1.0 like Flickr and twitter, just create the above files using the twitter or flickr version as a template, and modify them as needed (for the .service file, you could use flickr-sharing.service); in trello.provider you'll need to change the API endpoints as following:

And of course, change the other fields (callback URL, client ID and secret) to match those you set when you registered your app with Trello.
If all goes well, you'll be able to create a Trello account from the "Online Accounts" panel in the System Settings.

Since the approach that mardy uses isn't actually available to apps under confinement on Ubuntu Touch, it is necessary to do the OAuth dance your self. Essentially, you need to load the login page in a WebView and then intercept the response using the onUrlChanged signal to extract the auth token. Below is an example using StackExchange's own OAuth implementation.