WIP JWT
This commit is contained in:
		@@ -1,9 +1,40 @@
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
#include <string.h>
 | 
					#include <string.h>
 | 
				
			||||||
 | 
					#include <stdio.h>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#include "jwt.h"
 | 
					#include "jwt.h"
 | 
				
			||||||
 | 
					#include "dev_name.h"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#include "esp_log.h"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					static const char *TAG = "jwt";
 | 
				
			||||||
 | 
					
 | 
				
			||||||
char *jwt_gen(cJSON *payload)
 | 
					char *jwt_gen(cJSON *payload)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
 | 
					    char *kid = dev_name();
 | 
				
			||||||
 | 
					    if (!kid)
 | 
				
			||||||
 | 
					    {
 | 
				
			||||||
 | 
					        ESP_LOGE(TAG, "Failed to allocated memory to store device name!");
 | 
				
			||||||
 | 
					        return NULL;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    cJSON *header_json = cJSON_CreateObject();
 | 
				
			||||||
 | 
					    if (!header_json)
 | 
				
			||||||
 | 
					        return NULL;
 | 
				
			||||||
 | 
					    cJSON_AddStringToObject(header_json, "alg", "ES256");
 | 
				
			||||||
 | 
					    cJSON_AddStringToObject(header_json, "typ", "JWT");
 | 
				
			||||||
 | 
					    cJSON_AddStringToObject(header_json, "kid", kid);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    char *header = cJSON_PrintUnformatted(header_json);
 | 
				
			||||||
 | 
					    free(kid);
 | 
				
			||||||
 | 
					    cJSON_Delete(header_json);
 | 
				
			||||||
 | 
					    if (!header)
 | 
				
			||||||
 | 
					    {
 | 
				
			||||||
 | 
					        ESP_LOGE(TAG, "Failed to generate JSON header!");
 | 
				
			||||||
 | 
					        return NULL;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    printf("header: %s\n", header);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    return strdup("TODO:)");
 | 
					    return strdup("TODO:)");
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
		Reference in New Issue
	
	Block a user