completed get_handle_login
This commit is contained in:
parent
7f4a319353
commit
6b84d45674
29
src/http.c
29
src/http.c
@ -277,6 +277,25 @@ guess_mime_type(char *filename)
|
||||
return "text/plain";
|
||||
}
|
||||
|
||||
/* Check a token is not expired. */
|
||||
static bool validate_token_exp(struct http_transaction *ta, char* grants) {
|
||||
|
||||
char *gs = calloc(strlen(grants) + 1, sizeof(char));
|
||||
memcpy(gs, grants, strlen(grants) + 1);
|
||||
char *end;
|
||||
char *expire = strtok_r(gs, "{\":, }", &end);
|
||||
while (expire != NULL) {
|
||||
if (!strcasecmp(expire, "exp")) {
|
||||
int exp = atoi(strtok_r(NULL, "{\":, }", &end));
|
||||
if (time(NULL) >= exp) {
|
||||
return false;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/* Handle HTTP transaction for static files. */
|
||||
static bool
|
||||
handle_static_asset(struct http_transaction *ta, char *basedir)
|
||||
@ -345,16 +364,16 @@ static bool get_handle_login(struct http_transaction *ta) {
|
||||
return send_error(ta, HTTP_OK, "{}\n");
|
||||
}
|
||||
|
||||
// check expiration, still implementing
|
||||
if (1) {
|
||||
if (!validate_token_exp(ta, grants)) {
|
||||
return send_error(ta, HTTP_PERMISSION_DENIED,"Forbidden.\n");
|
||||
}
|
||||
|
||||
// Still implementing
|
||||
char *json = buffer_ensure_capacity(&ta->resp_body, MAX_HEADER_LEN);
|
||||
int len = snprintf(json, strlen(grants) + 2, "%s\n", grants);
|
||||
int length = len > MAX_HEADER_LEN ? MAX_HEADER_LEN - 1 : len;
|
||||
ta->resp_body.len += length;
|
||||
|
||||
return send_response(ta);
|
||||
|
||||
|
||||
}
|
||||
|
||||
static int val_api_url(struct http_transaction *ta) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user