From 306cf74eb0101a12b51549866a4d60296618ee0b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=A6=8C=EA=A6=AB=EA=A6=B6=EA=A6=8F=EA=A7=80=EA=A6=A6?= =?UTF-8?q?=EA=A6=BF=EA=A6=A7=EA=A6=AE=EA=A6=91=EA=A6=A9=EA=A6=AD=EA=A7=80?= Date: Wed, 14 Sep 2022 18:19:14 +0800 Subject: OAuth part The minimum to pass all authentications and arrive at the embedded app index. This library is to be used with shopify-app-template-c for now, as it assumes the existence of shopify.app.toml in the parent directory, and index.html in the frontend directory. --- token.h | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 token.h (limited to 'token.h') diff --git a/token.h b/token.h new file mode 100644 index 0000000..0154ef5 --- /dev/null +++ b/token.h @@ -0,0 +1,26 @@ +#include + +static inline void token_parse(char *tok, struct session *session) +{ + json_tokener *tokener = json_tokener_new(); + json_object *obj = json_tokener_parse_ex(tokener, tok, strlen(tok)); + struct json_object_iterator iter = json_object_iter_begin(obj); + struct json_object_iterator iter_end = json_object_iter_end(obj); + while (!json_object_iter_equal(&iter, &iter_end)) { + if (!strcmp(json_object_iter_peek_name(&iter), + "access_token")) { + const char *val = json_object_get_string( + json_object_iter_peek_value(&iter)); + session->token = malloc(strlen(val) + 1); + strcpy(session->token, val); + } else if (!strcmp(json_object_iter_peek_name(&iter), + "scope")) { + const char *val = json_object_get_string( + json_object_iter_peek_value(&iter)); + session->scope = malloc(strlen(val) + 1); + strcpy(session->scope, val); + } + json_object_iter_next(&iter); + } + json_tokener_free(tokener); +} -- cgit v1.2.3