As of now, the rewrite of Cawbird (a GTK Twitter client) can authenticate at the API-Servers from Twitter using both OAuth 1.0a and 2.0.
The former requires us to fetch an token for the client before building the url to send the user for authentication to, which is where an asynchronous method is practical.
The latter however only builds the url locally and therefore don’t need an asynchronous method.
Now, due to how I designed the backend, the implementation to build these authentication url is done in an asynchronous method (as I have a base class defining the methods for the frontend that are implemented in sub-classes).
However, I found out today that running Rest.OAuth2Proxy.build_authentication_url
in an asynchronous method leads to an error.
When I also set the OAuth state
variable to be saved, the program will crash when finalizing the class and freeing the stored state variable.
See the following code:
class TestClass : Object {
private Rest.OAuth2Proxy proxy;
private string? state = null;
public TestClass () {
proxy = new Rest.OAuth2Proxy ("example://authorize",
"example://token",
"example://redirect",
"some_token",
"some_secret",
"example://api");
}
public async string build_url () {
var auth_challenge = new Rest.PkceCodeChallenge.random ();
return proxy.build_authorization_url (auth_challenge.get_challenge (),
"scopes",
out state);
}
}
void main () {
var test = new TestClass ();
var loop = new MainLoop ();
test.build_url.begin ((obj, res) => {
string url = test.build_url.end (res);
print (@"Look at this url: $(url)\n");
loop.quit();
});
loop.run();
}
When it is run as is, it should result in an crash with one of the following messages:
free(): invalid pointer
double free or corruption (out)
free(): invalid size
When making build_url
a synchronous method it will work without an problem though.
Now, my question is if running this method asynchronously should just not be done (and is therefore my problem), or if this is an bug from either librest
or valac
that should be resolved.