diary

Text-based journaling program
git clone https://git.in0rdr.ch/diary.git
Log | Files | Refs | README | LICENSE

commit be582030e74da2163b17147449921520ab4e0dd1
parent e503b2ddb96aacb9154e88470cdea0bb8f0d6560
Author: Andreas Gruhler <agruhl@gmx.ch>
Date:   Sat, 22 May 2021 11:11:11 +0200

fix segfault after oauth

The global var access_token did not get initialized the first time it
was used in a call to caldav_req(), because the tokenfile was only
re-read on a call to get_access_token() with refresh=true.

This flag refresh=true is used to refresh with the refresh token from
the tokenfile. The global vars access_token and refresh_token however
should be re-read from the token file in both case, refres=true and
refresh=false.

Diffstat:
Mcaldav.c | 22+++++++++++-----------
1 file changed, 11 insertions(+), 11 deletions(-)

diff --git a/caldav.c b/caldav.c @@ -195,17 +195,16 @@ void get_access_token(char* code, char* verifier, bool refresh) { if (res != CURLE_OK) { fprintf(stderr, "curl_easy_perform() failed: %s\n", curl_easy_strerror(res)); return; - } else if (refresh) { - // update global variables from tokenfile - read_tokenfile(); - // Make sure the refresh token is re-written and persistet - // to the tokenfile for further requests, becaues the - // is not returned by the refresh_token call: - // https://developers.google.com/identity/protocols/oauth2/native-app#offline - write_tokenfile(); } + // update global variables from tokenfile + // this will also init the access_token var the first time + read_tokenfile(); + // Make sure the refresh token is re-written and persistet + // to the tokenfile for further requests, because the + // is not returned by the refresh_token call: + // https://developers.google.com/identity/protocols/oauth2/native-app#offline + write_tokenfile(); } - } char* get_oauth_code(const char* verifier, WINDOW* header) { @@ -510,12 +509,13 @@ void caldav_sync(struct tm* date, WINDOW* header) { } char* principal_postfields = "<d:propfind xmlns:d='DAV:' xmlns:cs='http://calendarserver.org/ns/'>" - "<d:prop><d:current-user-principal/></d:prop>" - "</d:propfind>"; + "<d:prop><d:current-user-principal/></d:prop>" + "</d:propfind>"; // check if we can use the token from the tokenfile char* user_principal = caldav_req(date, GOOGLE_CALDAV_URI, "PROPFIND", principal_postfields, 0); + fprintf(stderr, "User principal: %s\n", user_principal); if (user_principal == NULL) { fprintf(stderr, "Unable to fetch principal, refreshing API token.\n");