diff options
author | ꦌꦫꦶꦏ꧀ꦦꦿꦧꦮꦑꦩꦭ꧀ <erik@darapsa.co.id> | 2022-09-19 20:13:08 +0800 |
---|---|---|
committer | ꦌꦫꦶꦏ꧀ꦦꦿꦧꦮꦑꦩꦭ꧀ <erik@darapsa.co.id> | 2022-09-19 20:13:08 +0800 |
commit | e594d063888db9f36a4682bc31348cea952eadaa (patch) | |
tree | b899fa56ce1f2a05b0cafb59b868e5fc406d7e39 /accesstoken.h | |
parent | 69ff68be8fa52ac741146789f7be024ada28a4ad (diff) |
First attempt to validate session token
Function & variable names are changed for consistency & conventions.
Tries to print out shop name from referer header, and the session token
details.
Diffstat (limited to 'accesstoken.h')
-rw-r--r-- | accesstoken.h | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/accesstoken.h b/accesstoken.h new file mode 100644 index 0000000..009cdb0 --- /dev/null +++ b/accesstoken.h @@ -0,0 +1,27 @@ +#include <json.h> + +static inline void accesstoken_parse(const char *tok, + struct shopify_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->access_token = malloc(strlen(val) + 1); + strcpy(session->access_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); +} |