From 7a22cab34332707ea2fe5d3e690033c424886c9b Mon Sep 17 00:00:00 2001 From: Kelly Rauchenberger Date: Sun, 15 Oct 2017 13:07:39 -0400 Subject: Changed auth password to token --- gen3uploader.cfg | 2 +- source/http.c | 17 +++++------------ source/http.h | 5 ++--- source/main.c | 2 +- 4 files changed, 9 insertions(+), 17 deletions(-) diff --git a/gen3uploader.cfg b/gen3uploader.cfg index 2d987d0..78f4748 100644 --- a/gen3uploader.cfg +++ b/gen3uploader.cfg @@ -1,6 +1,6 @@ { "url": "", "username": "", - "password": "", + "token": "", "certificate": "" } \ No newline at end of file diff --git a/source/http.c b/source/http.c index be62dce..2ac10fb 100644 --- a/source/http.c +++ b/source/http.c @@ -146,23 +146,13 @@ int submitToApi( WOLFSSL_CTX* sslContext, cJSON* data, const char* username, - const char* password) + const char* token) { // Form request body. cJSON* jRequestBody = cJSON_CreateObject(); cJSON_AddItemToObject(jRequestBody, "game", data); - cJSON_AddItemToObject( - jRequestBody, - "username", - cJSON_CreateString(username)); - - cJSON_AddItemToObject( - jRequestBody, - "password", - cJSON_CreateString(password)); - const char* requestBody = cJSON_PrintUnformatted(jRequestBody); // Gather data from endpoint URL. @@ -304,7 +294,10 @@ int submitToApi( r += sprintf(r, "POST %s HTTP/1.1\r\n", httpPath); r += sprintf(r, "Host: %s\r\n", httpHost); r += sprintf(r, "Content-Type: application/json\r\n"); - r += sprintf(r, "Content-Length: %d\r\n\r\n", strlen(requestBody)); + r += sprintf(r, "Content-Length: %d\r\n", strlen(requestBody)); + r += sprintf(r, "X-User-Login: %s\r\n", username); + r += sprintf(r, "X-User-Token: %s\r\n", token); + r += sprintf(r, "\r\n"); int result = tcpWrite( secure, diff --git a/source/http.h b/source/http.h index 9597a1d..ed8c017 100644 --- a/source/http.h +++ b/source/http.h @@ -24,14 +24,13 @@ typedef enum { } http_res; /** - * Submits a JSON request to a web service. Takes ownership of the cJSON object, - * because it needs to embed authentication data in it. + * Submits a JSON request to a web service. Takes ownership of the cJSON object. */ int submitToApi( const char* endpoint, WOLFSSL_CTX* sslContext, cJSON* data, const char* username, - const char* password); + const char* token); #endif /* end of include guard: HTTP_H_A46C206E */ diff --git a/source/main.c b/source/main.c index 6c97255..2ce314e 100644 --- a/source/main.c +++ b/source/main.c @@ -425,7 +425,7 @@ void* extractor(void* userdata) sslContext, root, cJSON_GetObjectItem(config, "username")->valuestring, - cJSON_GetObjectItem(config, "password")->valuestring); + cJSON_GetObjectItem(config, "token")->valuestring); printf("Result: %d\n", result); -- cgit 1.4.1