Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Google OAuth 2.0 Refresh-Token persistence Qt

Tags:

google-api

qt

I want to get data via the Google-API from a Qt 5.9 C++ desktop application.

Using the QOAuth2AuthorizationCodeFlow I can log in and access any data I need.

The problem now is that I cannot find out how to store the refresh-token, so that I do not have go through the whole auth process every time the app is started.

The QOAuth2AuthorizationCodeFlow does not seem to have an interface for accessing the refresh-token.

I tried manually requesting a refresh-token, but only ever managed to get an error message back that the request did not have enough authentication scopes. The documentation for the Token Service API does not mention which scope to add to fix this.

How can I avoid re-authentication each time my app is started (even if it is just seconds apart)?

like image 624
Dragonseel Avatar asked Jan 17 '26 15:01

Dragonseel


1 Answers

I ended up solving the problem using a small library.

Link to the o2 library on github.

This library which is OpenSource with a very open license is easy to use and easy to add to a CMake build.

Download the sources, and build, compile and install them using CMake. The default build options require the external library "QKeychain" but it works fine for me when disabling the dependency in the CMake options. Then add the .lib-files and include folder to the CMakeLists.txt of your project.

Using the library is just creating a special O2Google object for authentication and a O2Requestor to make authenticated requests to the API. The refresh_token will be automatically and persistently stored so that no re-authentication is needed on every start of the app.

like image 166
Dragonseel Avatar answered Jan 20 '26 08:01

Dragonseel



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!