commit ec51d59
default
·
2023-04-15 07:44:09 +0000 UTC
parent 9e7a77c
Some fixes to allow Megalodon to work. The instance object was wrong and the oauth args can appear as JSON.
1 files changed,
+29,
-18
+29,
-18
1@@ -227,17 +227,25 @@ int oauth_post_handler(const xs_dict *req, const char *q_path,
2 }*/
3
4 int status = 404;
5- xs_dict *msg = xs_dict_get(req, "p_vars");
6- xs *cmd = xs_replace(q_path, "/oauth", "");
7+
8+ char *i_ctype = xs_dict_get(req, "content-type");
9+ xs *args = NULL;
10+
11+ if (i_ctype && xs_startswith(i_ctype, "application/json"))
12+ args = xs_json_loads(payload);
13+ else
14+ args = xs_dup(xs_dict_get(req, "p_vars"));
15+
16+ xs *cmd = xs_replace(q_path, "/oauth", "");
17
18 srv_debug(1, xs_fmt("oauth_post_handler %s", q_path));
19
20 if (strcmp(cmd, "/x-snac-login") == 0) {
21- const char *login = xs_dict_get(msg, "login");
22- const char *passwd = xs_dict_get(msg, "passwd");
23- const char *redir = xs_dict_get(msg, "redir");
24- const char *cid = xs_dict_get(msg, "cid");
25- const char *state = xs_dict_get(msg, "state");
26+ const char *login = xs_dict_get(args, "login");
27+ const char *passwd = xs_dict_get(args, "passwd");
28+ const char *redir = xs_dict_get(args, "redir");
29+ const char *cid = xs_dict_get(args, "cid");
30+ const char *state = xs_dict_get(args, "state");
31
32 const char *host = xs_dict_get(srv_config, "host");
33
34@@ -293,11 +301,12 @@ int oauth_post_handler(const xs_dict *req, const char *q_path,
35 }
36 else
37 if (strcmp(cmd, "/token") == 0) {
38- const char *gtype = xs_dict_get(msg, "grant_type");
39- const char *code = xs_dict_get(msg, "code");
40- const char *cid = xs_dict_get(msg, "client_id");
41- const char *csec = xs_dict_get(msg, "client_secret");
42- const char *ruri = xs_dict_get(msg, "redirect_uri");
43+ const char *gtype = xs_dict_get(args, "grant_type");
44+ const char *code = xs_dict_get(args, "code");
45+ const char *cid = xs_dict_get(args, "client_id");
46+ const char *csec = xs_dict_get(args, "client_secret");
47+ const char *ruri = xs_dict_get(args, "redirect_uri");
48+ const char *scope = xs_dict_get(args, "scope");
49 xs *wrk = NULL;
50
51 /* no client_secret? check if it's inside an authorization header
52@@ -342,6 +351,9 @@ int oauth_post_handler(const xs_dict *req, const char *q_path,
53 rsp = xs_dict_append(rsp, "token_type", "Bearer");
54 rsp = xs_dict_append(rsp, "created_at", cat);
55
56+ if (!xs_is_null(scope))
57+ rsp = xs_dict_append(rsp, "scope", scope);
58+
59 *body = xs_json_dumps_pp(rsp, 4);
60 *ctype = "application/json";
61 status = 200;
62@@ -368,9 +380,9 @@ int oauth_post_handler(const xs_dict *req, const char *q_path,
63 }
64 else
65 if (strcmp(cmd, "/revoke") == 0) {
66- const char *cid = xs_dict_get(msg, "client_id");
67- const char *csec = xs_dict_get(msg, "client_secret");
68- const char *tokid = xs_dict_get(msg, "token");
69+ const char *cid = xs_dict_get(args, "client_id");
70+ const char *csec = xs_dict_get(args, "client_secret");
71+ const char *tokid = xs_dict_get(args, "token");
72
73 if (cid && csec && tokid) {
74 xs *token = token_get(tokid);
75@@ -989,6 +1001,7 @@ int mastoapi_get_handler(const xs_dict *req, const char *q_path,
76 xs *ins = xs_dict_new();
77 const char *host = xs_dict_get(srv_config, "host");
78
79+ ins = xs_dict_append(ins, "uri", host);
80 ins = xs_dict_append(ins, "domain", host);
81 ins = xs_dict_append(ins, "title", host);
82 ins = xs_dict_append(ins, "version", "4.0.0 (not true; really " USER_AGENT ")");
83@@ -996,9 +1009,7 @@ int mastoapi_get_handler(const xs_dict *req, const char *q_path,
84 ins = xs_dict_append(ins, "description", host);
85
86 xs *susie = xs_fmt("%s/susie.png", srv_baseurl);
87- xs *d1 = xs_dict_new();
88- d1 = xs_dict_append(d1, "url", susie);
89- ins = xs_dict_append(ins, "thumbnail", d1);
90+ ins = xs_dict_append(ins, "thumbnail", susie);
91
92 xs *d2 = xs_dict_new();
93 d2 = xs_dict_append(d2, "email", "admin@localhost");