mirror of
https://forge.fsky.io/lda/Parsee.git
synced 2026-03-13 22:45:12 +00:00
[ADD/WIP] Add some HTTP request code
We can now *register* users!
This commit is contained in:
parent
47c98cbbe3
commit
0fa95c2d14
12 changed files with 320 additions and 11 deletions
56
src/AS.c
Normal file
56
src/AS.c
Normal file
|
|
@ -0,0 +1,56 @@
|
|||
#include <AS.h>
|
||||
|
||||
#include <Cytoplasm/Memory.h>
|
||||
#include <Cytoplasm/Str.h>
|
||||
#include <Cytoplasm/Log.h>
|
||||
|
||||
#include <string.h>
|
||||
|
||||
#include <Matrix.h>
|
||||
|
||||
HashMap *
|
||||
ASVerifyRequest(ParseeHttpArg *arg)
|
||||
{
|
||||
HashMap *ret = NULL;
|
||||
HashMap *params;
|
||||
char *authorisation;
|
||||
if (!arg)
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
params = HttpRequestHeaders(arg->ctx);
|
||||
authorisation = HashMapGet(params, "authorization");
|
||||
|
||||
if (!authorisation || strncmp(authorisation, "Bearer ", 7))
|
||||
{
|
||||
Log(LOG_INFO, "Bad auth %s", authorisation);
|
||||
HttpResponseStatus(arg->ctx, HTTP_FORBIDDEN);
|
||||
ret = MatrixCreateError("M_MISSING_TOKEN", "No 'hs_token' given in.");
|
||||
goto end;
|
||||
}
|
||||
|
||||
authorisation += 7;
|
||||
if (!StrEquals(authorisation, arg->data->config->hs_token))
|
||||
{
|
||||
HttpResponseStatus(arg->ctx, HTTP_FORBIDDEN);
|
||||
ret = MatrixCreateError("M_FORBIDDEN","Incorrect authorisation given");
|
||||
goto end;
|
||||
}
|
||||
end:
|
||||
return ret;
|
||||
}
|
||||
|
||||
void
|
||||
ASAuthenticateRequest(ParseeConfig *data, HttpClientContext *ctx)
|
||||
{
|
||||
char *bearer;
|
||||
if (!data || !ctx)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
bearer = StrConcat(2, "Bearer ", data->as_token);
|
||||
HttpRequestHeader(ctx, "Authorization", bearer);
|
||||
Free(bearer);
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue