Fix bug where you couldn't stay logged in with a web browser, add last_used time for eventually removing client_app credentials automatically

master
teknomunk 6 months ago
parent 07f1b937ee
commit d08b7a0ce7

@ -12,6 +12,7 @@
// Submodules // Submodules
#include "form.h" #include "form.h"
#include "format.h"
#include "http/server/request.h" #include "http/server/request.h"
// Platform Headers // Platform Headers
@ -55,6 +56,11 @@ bool handle_admin_initial_owner_setup( struct http_request* req )
// Create owner account // Create owner account
struct account* owner = account_new(); struct account* owner = account_new();
owner->id = owner_account_id; owner->id = owner_account_id;
owner->server = strdup(g_server->domain);
owner->account_url = aformat("https://%s/owner/actor", g_server->domain );
owner->banner = aformat("https://%s/owner/banner.blob", g_server->domain );
owner->avatar.url = aformat("https://%s/owner/avatar.blob", g_server->domain );
owner->avatar.static_url = aformat("https://%s/owner/avatar.blob", g_server->domain );
account_save(owner); account_save(owner);
// Create home timeline account // Create home timeline account
@ -89,6 +95,7 @@ bool handle_admin_initial_owner_setup( struct http_request* req )
confirm = strdup(form_pull_parser_read_value(fp)); confirm = strdup(form_pull_parser_read_value(fp));
} else if( 0 == strcmp(key,"handle") ) { } else if( 0 == strcmp(key,"handle") ) {
owner->handle = strdup(form_pull_parser_read_value(fp)); owner->handle = strdup(form_pull_parser_read_value(fp));
owner->display_name = strdup(owner->handle);
account_save(owner); account_save(owner);
} }
} }

@ -92,6 +92,8 @@ bool check_bearer_token( const char* auth_token )
client_app_free(app); client_app_free(app);
return false; return false;
} }
app->last_used = time(NULL);
client_app_save(app);
client_app_free(app); client_app_free(app);
return true; return true;

@ -18,6 +18,7 @@ static struct json_object_field client_app_layout[] = {
JSON_FIELD_STRING( auth_code, false ), JSON_FIELD_STRING( auth_code, false ),
JSON_FIELD_STRING( access_token, false ), JSON_FIELD_STRING( access_token, false ),
JSON_FIELD_STRING( redirect_uri, false ), JSON_FIELD_STRING( redirect_uri, false ),
JSON_FIELD_DATETIME( last_used, false ),
{ {
.key = "secret", .key = "secret",
.offset = offsetof( struct client_app, client.secret ), .offset = offsetof( struct client_app, client.secret ),
@ -69,6 +70,7 @@ struct client_app* client_app_new( const char* client_name )
app->auth_code = NULL; app->auth_code = NULL;
app->redirect_uri = NULL; app->redirect_uri = NULL;
app->access_token = NULL; app->access_token = NULL;
app->last_used = time(NULL);
client_app_save(app); client_app_save(app);
return app; return app;

@ -1,5 +1,7 @@
#pragma once #pragma once
#include <time.h>
struct client_app struct client_app
{ {
struct { struct {
@ -11,6 +13,7 @@ struct client_app
char* redirect_uri; char* redirect_uri;
char* auth_code; char* auth_code;
char* access_token; char* access_token;
time_t last_used;
// auth_expires // auth_expires
}; };

@ -79,6 +79,8 @@ void app_args_load()
} else if( g_server->tor_hidden_service ) { } else if( g_server->tor_hidden_service ) {
g_server->domain = strdup(g_server->tor_hidden_service); g_server->domain = strdup(g_server->tor_hidden_service);
} }
printf( "Using domain: %s\n", g_server->domain );
} }
struct app_args* app_args_new( int argc, char** argv ) struct app_args* app_args_new( int argc, char** argv )
{ {

Loading…
Cancel
Save