diff options
| author | ꦌꦫꦶꦏ꧀ꦦꦿꦧꦮꦑꦩꦭ꧀ <erik@darapsa.co.id> | 2022-09-14 18:19:14 +0800 |
|---|---|---|
| committer | ꦌꦫꦶꦏ꧀ꦦꦿꦧꦮꦑꦩꦭ꧀ <erik@darapsa.co.id> | 2022-09-14 18:19:14 +0800 |
| commit | 306cf74eb0101a12b51549866a4d60296618ee0b (patch) | |
| tree | 89fe13b234f40f97de84cdb6610bcd11e1d47a88 /token.h | |
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.
Diffstat (limited to 'token.h')
| -rw-r--r-- | token.h | 26 |
1 files changed, 26 insertions, 0 deletions
@@ -0,0 +1,26 @@ +#include <json.h> + +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); +} |