Zephyr Project API 4.0.0
A Scalable Open Source RTOS
Loading...
Searching...
No Matches
JSON Web Token (JWT)

JSON Web Token (JWT) - RFC 7519. More...

Data Structures

struct  jwt_builder
 JWT data tracking. More...
 

Functions

int jwt_init_builder (struct jwt_builder *builder, char *buffer, size_t buffer_size)
 Initialize the JWT builder.
 
int jwt_add_payload (struct jwt_builder *builder, int32_t exp, int32_t iat, const char *aud)
 Add JWT payload.
 
int jwt_sign (struct jwt_builder *builder, const char *der_key, size_t der_key_len)
 Sign the JWT.
 

Detailed Description

JSON Web Token (JWT) - RFC 7519.

Function Documentation

◆ jwt_add_payload()

int jwt_add_payload ( struct jwt_builder builder,
int32_t  exp,
int32_t  iat,
const char *  aud 
)

#include <include/zephyr/data/jwt.h>

Add JWT payload.

Add JWT payload to a previously initialized builder with the following fields:

  • Expiration Time
  • Issued At
  • Audience

See RFC 7519 section 4.1 to get more information about these fields.

Parameters
builderA previously initialized builder.
expExpiration Time (epoch format).
iatIssued At (epoch format).
audAudience.
Return values
0Success.
<0Failure.

◆ jwt_init_builder()

int jwt_init_builder ( struct jwt_builder builder,
char *  buffer,
size_t  buffer_size 
)

#include <include/zephyr/data/jwt.h>

Initialize the JWT builder.

Initialize the given JWT builder for the creation of a fresh token. The buffer size should be long enough to store the entire token.

Parameters
builderThe builder to initialize.
bufferThe buffer to write the token to.
buffer_sizeThe size of this buffer. The token will be NULL terminated, which needs to be allowed for in this size.
Return values
0Success.
-ENOSPCBuffer is insufficient to initialize.

◆ jwt_sign()

int jwt_sign ( struct jwt_builder builder,
const char *  der_key,
size_t  der_key_len 
)

#include <include/zephyr/data/jwt.h>

Sign the JWT.

Sign a previously initialized with payload JWT.

Parameters
builderA previously initialized builder with payload.
der_keyPrivate key to use in DER format.
der_key_lenSize of the private key in bytes.
Return values
0Success.
<0Failure.