diff options
| author | 2023-04-15 09:44:09 +0200 | |
|---|---|---|
| committer | 2023-04-15 09:44:09 +0200 | |
| commit | ec51d59e2457aa28398b908015819ece0083fbbe (patch) | |
| tree | 063e56f35f6e5d4eb8b7a29525232b1a7f5a803b | |
| parent | New mastoapi to clear all notifications. (diff) | |
| download | snac2-ec51d59e2457aa28398b908015819ece0083fbbe.tar.gz snac2-ec51d59e2457aa28398b908015819ece0083fbbe.tar.xz snac2-ec51d59e2457aa28398b908015819ece0083fbbe.zip | |
Some fixes to allow Megalodon to work.
The instance object was wrong and the oauth args can appear as JSON.
| -rw-r--r-- | mastoapi.c | 47 |
1 files changed, 29 insertions, 18 deletions
| @@ -227,17 +227,25 @@ int oauth_post_handler(const xs_dict *req, const char *q_path, | |||
| 227 | }*/ | 227 | }*/ |
| 228 | 228 | ||
| 229 | int status = 404; | 229 | int status = 404; |
| 230 | xs_dict *msg = xs_dict_get(req, "p_vars"); | 230 | |
| 231 | xs *cmd = xs_replace(q_path, "/oauth", ""); | 231 | char *i_ctype = xs_dict_get(req, "content-type"); |
| 232 | xs *args = NULL; | ||
| 233 | |||
| 234 | if (i_ctype && xs_startswith(i_ctype, "application/json")) | ||
| 235 | args = xs_json_loads(payload); | ||
| 236 | else | ||
| 237 | args = xs_dup(xs_dict_get(req, "p_vars")); | ||
| 238 | |||
| 239 | xs *cmd = xs_replace(q_path, "/oauth", ""); | ||
| 232 | 240 | ||
| 233 | srv_debug(1, xs_fmt("oauth_post_handler %s", q_path)); | 241 | srv_debug(1, xs_fmt("oauth_post_handler %s", q_path)); |
| 234 | 242 | ||
| 235 | if (strcmp(cmd, "/x-snac-login") == 0) { | 243 | if (strcmp(cmd, "/x-snac-login") == 0) { |
| 236 | const char *login = xs_dict_get(msg, "login"); | 244 | const char *login = xs_dict_get(args, "login"); |
| 237 | const char *passwd = xs_dict_get(msg, "passwd"); | 245 | const char *passwd = xs_dict_get(args, "passwd"); |
| 238 | const char *redir = xs_dict_get(msg, "redir"); | 246 | const char *redir = xs_dict_get(args, "redir"); |
| 239 | const char *cid = xs_dict_get(msg, "cid"); | 247 | const char *cid = xs_dict_get(args, "cid"); |
| 240 | const char *state = xs_dict_get(msg, "state"); | 248 | const char *state = xs_dict_get(args, "state"); |
| 241 | 249 | ||
| 242 | const char *host = xs_dict_get(srv_config, "host"); | 250 | const char *host = xs_dict_get(srv_config, "host"); |
| 243 | 251 | ||
| @@ -293,11 +301,12 @@ int oauth_post_handler(const xs_dict *req, const char *q_path, | |||
| 293 | } | 301 | } |
| 294 | else | 302 | else |
| 295 | if (strcmp(cmd, "/token") == 0) { | 303 | if (strcmp(cmd, "/token") == 0) { |
| 296 | const char *gtype = xs_dict_get(msg, "grant_type"); | 304 | const char *gtype = xs_dict_get(args, "grant_type"); |
| 297 | const char *code = xs_dict_get(msg, "code"); | 305 | const char *code = xs_dict_get(args, "code"); |
| 298 | const char *cid = xs_dict_get(msg, "client_id"); | 306 | const char *cid = xs_dict_get(args, "client_id"); |
| 299 | const char *csec = xs_dict_get(msg, "client_secret"); | 307 | const char *csec = xs_dict_get(args, "client_secret"); |
| 300 | const char *ruri = xs_dict_get(msg, "redirect_uri"); | 308 | const char *ruri = xs_dict_get(args, "redirect_uri"); |
| 309 | const char *scope = xs_dict_get(args, "scope"); | ||
| 301 | xs *wrk = NULL; | 310 | xs *wrk = NULL; |
| 302 | 311 | ||
| 303 | /* no client_secret? check if it's inside an authorization header | 312 | /* no client_secret? check if it's inside an authorization header |
| @@ -342,6 +351,9 @@ int oauth_post_handler(const xs_dict *req, const char *q_path, | |||
| 342 | rsp = xs_dict_append(rsp, "token_type", "Bearer"); | 351 | rsp = xs_dict_append(rsp, "token_type", "Bearer"); |
| 343 | rsp = xs_dict_append(rsp, "created_at", cat); | 352 | rsp = xs_dict_append(rsp, "created_at", cat); |
| 344 | 353 | ||
| 354 | if (!xs_is_null(scope)) | ||
| 355 | rsp = xs_dict_append(rsp, "scope", scope); | ||
| 356 | |||
| 345 | *body = xs_json_dumps_pp(rsp, 4); | 357 | *body = xs_json_dumps_pp(rsp, 4); |
| 346 | *ctype = "application/json"; | 358 | *ctype = "application/json"; |
| 347 | status = 200; | 359 | status = 200; |
| @@ -368,9 +380,9 @@ int oauth_post_handler(const xs_dict *req, const char *q_path, | |||
| 368 | } | 380 | } |
| 369 | else | 381 | else |
| 370 | if (strcmp(cmd, "/revoke") == 0) { | 382 | if (strcmp(cmd, "/revoke") == 0) { |
| 371 | const char *cid = xs_dict_get(msg, "client_id"); | 383 | const char *cid = xs_dict_get(args, "client_id"); |
| 372 | const char *csec = xs_dict_get(msg, "client_secret"); | 384 | const char *csec = xs_dict_get(args, "client_secret"); |
| 373 | const char *tokid = xs_dict_get(msg, "token"); | 385 | const char *tokid = xs_dict_get(args, "token"); |
| 374 | 386 | ||
| 375 | if (cid && csec && tokid) { | 387 | if (cid && csec && tokid) { |
| 376 | xs *token = token_get(tokid); | 388 | xs *token = token_get(tokid); |
| @@ -989,6 +1001,7 @@ int mastoapi_get_handler(const xs_dict *req, const char *q_path, | |||
| 989 | xs *ins = xs_dict_new(); | 1001 | xs *ins = xs_dict_new(); |
| 990 | const char *host = xs_dict_get(srv_config, "host"); | 1002 | const char *host = xs_dict_get(srv_config, "host"); |
| 991 | 1003 | ||
| 1004 | ins = xs_dict_append(ins, "uri", host); | ||
| 992 | ins = xs_dict_append(ins, "domain", host); | 1005 | ins = xs_dict_append(ins, "domain", host); |
| 993 | ins = xs_dict_append(ins, "title", host); | 1006 | ins = xs_dict_append(ins, "title", host); |
| 994 | ins = xs_dict_append(ins, "version", "4.0.0 (not true; really " USER_AGENT ")"); | 1007 | ins = xs_dict_append(ins, "version", "4.0.0 (not true; really " USER_AGENT ")"); |
| @@ -996,9 +1009,7 @@ int mastoapi_get_handler(const xs_dict *req, const char *q_path, | |||
| 996 | ins = xs_dict_append(ins, "description", host); | 1009 | ins = xs_dict_append(ins, "description", host); |
| 997 | 1010 | ||
| 998 | xs *susie = xs_fmt("%s/susie.png", srv_baseurl); | 1011 | xs *susie = xs_fmt("%s/susie.png", srv_baseurl); |
| 999 | xs *d1 = xs_dict_new(); | 1012 | ins = xs_dict_append(ins, "thumbnail", susie); |
| 1000 | d1 = xs_dict_append(d1, "url", susie); | ||
| 1001 | ins = xs_dict_append(ins, "thumbnail", d1); | ||
| 1002 | 1013 | ||
| 1003 | xs *d2 = xs_dict_new(); | 1014 | xs *d2 = xs_dict_new(); |
| 1004 | d2 = xs_dict_append(d2, "email", "admin@localhost"); | 1015 | d2 = xs_dict_append(d2, "email", "admin@localhost"); |