Exemple #1
0
/*
 * parse JWT payload
 */
static apr_byte_t apr_jwt_parse_payload(apr_pool_t *pool, const char *s_payload,
		apr_jwt_payload_t *payload, apr_jwt_error_t *err) {

	/* decode the JWT JSON payload */
	if (apr_jwt_base64url_decode_object(pool, s_payload, &payload->value,
			err) == FALSE)
		return FALSE;

	/* get the (optional) "issuer" value from the JSON payload */
	apr_jwt_get_string(pool, payload->value.json, "iss", FALSE, &payload->iss,
			NULL);

	/* get the (optional) "exp" value from the JSON payload */
	apr_jwt_get_timestamp(pool, payload->value.json, "exp", FALSE,
			&payload->exp,
			NULL);

	/* get the (optional) "iat" value from the JSON payload */
	apr_jwt_get_timestamp(pool, payload->value.json, "iat", FALSE,
			&payload->iat,
			NULL);

	/* get the (optional) "sub" value from the JSON payload */
	apr_jwt_get_string(pool, payload->value.json, "sub", FALSE, &payload->sub,
			NULL);

	return TRUE;
}
Exemple #2
0
/*
 * parse a JWT header
 */
apr_byte_t apr_jwt_parse_header(apr_pool_t *pool, const char *s_header,
                                apr_jwt_header_t *header) {

    /* decode the JWT JSON header */
    if (apr_jwt_base64url_decode_object(pool, s_header, &header->value) == FALSE)
        return FALSE;

    /* parse the (optional) signing algorithm */
    apr_jwt_get_string(pool, &header->value, "alg", &header->alg);

    /* check that the mandatory algorithm was set */
    if (header->alg == NULL)
        return FALSE;

    /* parse the (optional) kid */
    apr_jwt_get_string(pool, &header->value, "kid", &header->kid);

    /* parse the (optional) enc */
    apr_jwt_get_string(pool, &header->value, "enc", &header->enc);

    return TRUE;
}
Exemple #3
0
/*
 * parse a JWT header
 */
static apr_byte_t apr_jwt_parse_header_object(apr_pool_t *pool,
		const char *s_header, apr_jwt_header_t *header, apr_jwt_error_t *err) {

	/* decode the JWT JSON header */
	if (apr_jwt_base64url_decode_object(pool, s_header, &header->value,
			err) == FALSE)
		return FALSE;

	/* parse the (mandatory) signing algorithm */
	if (apr_jwt_get_string(pool, header->value.json, "alg", TRUE, &header->alg,
			err) == FALSE)
		return FALSE;

	/* parse the (optional) kid */
	apr_jwt_get_string(pool, header->value.json, "kid", FALSE, &header->kid,
			NULL);

	/* parse the (optional) enc */
	apr_jwt_get_string(pool, header->value.json, "enc", FALSE, &header->enc,
			NULL);

	return TRUE;
}