parent
4e351686f4
commit
75843983d6
@ -0,0 +1,8 @@
|
||||
{
|
||||
"id": 1,
|
||||
"name": "%s{app->client.name}",
|
||||
"website": null,
|
||||
"redirect_uri": "urn:ietf:wg:oauth:2.0:oob",
|
||||
"client_id": "%s{app->client.id}",
|
||||
"client_secret": "%s{app->client.secret}"
|
||||
}
|
@ -0,0 +1,21 @@
|
||||
#include "oauth.h"
|
||||
#include "http_server/http_request.h"
|
||||
|
||||
bool route_oauth_authorize( struct http_request* req )
|
||||
{
|
||||
http_request_send_headers( req, 200, "application/json", true );
|
||||
FILE* f = http_request_get_response_body( req );
|
||||
#define RENDER
|
||||
#include "view/login.html.inc"
|
||||
#undef RENDER
|
||||
return true;
|
||||
}
|
||||
|
||||
bool route_oauth( struct http_request* req )
|
||||
{
|
||||
if( http_request_route( req, "/authorize" ) ) {
|
||||
return route_oauth_authorize(req);
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
@ -0,0 +1,7 @@
|
||||
#pragma once
|
||||
|
||||
#include <stdbool.h>
|
||||
|
||||
struct http_request;
|
||||
|
||||
bool route_oauth( struct http_request* );
|
@ -0,0 +1,45 @@
|
||||
#include "client_app.h"
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
struct client_app* client_app_new( const char* client_name )
|
||||
{
|
||||
char id[33];
|
||||
for( int i = 0; i < 32; ++i ) {
|
||||
id[i] = 'a' + (rand() % 26);
|
||||
}
|
||||
id[32] = '\0';
|
||||
|
||||
char secret[65];
|
||||
for( int i = 0; i < 64; ++i ) {
|
||||
secret[i] = 'a' + (rand() % 26);
|
||||
}
|
||||
secret[64] = '\0';
|
||||
|
||||
struct client_app* app = malloc(sizeof(struct client_app));
|
||||
app->client.id = strdup(id);
|
||||
app->client.name = strdup(client_name);
|
||||
app->client.secret = strdup(secret);
|
||||
client_app_save(app);
|
||||
|
||||
return app;
|
||||
}
|
||||
|
||||
void client_app_save( struct client_app* app )
|
||||
{
|
||||
char filename[512];
|
||||
snprintf( filename, 512, "data/client_apps/%s.json", app->client.id );
|
||||
|
||||
char tmp_filename[512];
|
||||
snprintf( tmp_filename, 512, "%s.tmp-%d", filename, rand() );
|
||||
|
||||
FILE* f = fopen(tmp_filename, "w" );
|
||||
#define RENDER
|
||||
#include "model/client_app.json.inc"
|
||||
#undef RENDER
|
||||
fclose(f);
|
||||
rename( tmp_filename, filename );
|
||||
}
|
||||
|
@ -0,0 +1,15 @@
|
||||
#pragma once
|
||||
|
||||
struct client_app
|
||||
{
|
||||
struct {
|
||||
char* name;
|
||||
char* id;
|
||||
char* secret;
|
||||
} client;
|
||||
};
|
||||
|
||||
struct client_app* load_client_app_from_id( const char* client_id );
|
||||
struct client_app* client_app_new( const char* client_name );
|
||||
void client_app_save( struct client_app* app );
|
||||
|
@ -0,0 +1,7 @@
|
||||
{
|
||||
"client": {
|
||||
"id": "%s{app->client.id}",
|
||||
"secret": "%s{app->client.secret}",
|
||||
"name": "%s{app->client.name}"
|
||||
}
|
||||
}
|
@ -0,0 +1 @@
|
||||
TODO: show a login page
|
Loading…
Reference in new issue