Set token at start

FossilOrigin-Name: 6bddbaf860e0dadf443c554e170ac083ed871dff2b1c3c7950a8daa81dc221a7
This commit is contained in:
me@ow.nekobit.net 2022-02-18 04:35:08 +00:00
parent 1cb7c65c03
commit a74fd99b1e
3 changed files with 30 additions and 2 deletions

1
src/.#status.c Symbolic link
View file

@ -0,0 +1 @@
nekobit@toomuchram.2139:1645145990

View file

@ -19,6 +19,7 @@
#include <stdio.h>
#include <string.h>
#include <mastodont.h>
#include <stdlib.h>
#include "../config.h"
#include "index.h"
#include "page_config.h"
@ -26,6 +27,30 @@
#include "account.h"
#include "login.h"
#include "local_config.h"
#include "cookie.h"
void load_auth_token(mastodont_t* api)
{
struct http_cookie_info ck;
char* http_cookie = getenv("HTTP_COOKIE");
if (http_cookie)
{
char* cookie = malloc(strlen(http_cookie));
if (!cookie)
{
perror("malloc");
exit(1);
}
strcpy(cookie, http_cookie);
char* cookie_read = cookie;
if (cookie_get_val(cookie_read, "access_token", &ck) == 0)
{
mastodont_set_token(api, ck.val);
}
free(cookie);
}
}
int main(void)
{
@ -40,6 +65,9 @@ int main(void)
api.url = config_instance_url;
mastodont_init(&api);
// Used if the user is authenticated
load_auth_token(&api);
// Config defaults
g_config.theme = "ratfe20";

View file

@ -33,7 +33,7 @@ static void status_post(struct http_query_info* info, void* arg)
struct http_cookie_info ck;
struct mstdnt_storage storage;
// Cookie copy
// Cookie copy and read
char* http_cookie = getenv("HTTP_COOKIE");
char* cookie = malloc(strlen(http_cookie));
strcpy(cookie, http_cookie);
@ -41,7 +41,6 @@ static void status_post(struct http_query_info* info, void* arg)
if (cookie_get_val(cookie_read, "access_token", &ck) == 0)
{
api->token = ck.val;
struct mstdnt_create_status_args args = {
.content_type = "text/plain",
.expires_in = 0,