Skip to main content

odin_token_generator_sign

enum OdinError odin_token_generator_sign(struct OdinTokenGenerator *token_generator,
const char *body,
char *out_token,
uint32_t *out_token_length);

Overview

Signs the provided body using the key ID and access key stored in the token generator to sign the provided body, creating a JSON Web Token (JWT). The EdDSA (Ed25519) algorithm is used for the digital signature.

Parameters

NameTypeDescription
token_generatorstruct OdinTokenGenerator *The token generator handle.
bodyconst char *The JSON body to sign (should include uid, rid).
out_tokenchar *Buffer to write the JWT token to.
out_token_lengthuint32_t *Input: buffer size, Output: actual token length.

Return Value

TypeDescription
OdinErrorODIN_ERROR_SUCCESS on success.

Example

#include <odin.h>
#include <time.h>
// Using a JSON library like cJSON or similar is recommended for creating the body
// Here we assume a valid JSON string "claims"

const char *claims = "{\"uid\": \"user1\", \"rid\": \"room1\", \"aud\": \"gateway\"}";
char token[1024];
uint32_t token_len = sizeof(token);

OdinError err = odin_token_generator_sign(token_generator, claims, token, &token_len);
if (err == ODIN_ERROR_SUCCESS) {
// token now contains the signed JWT
}