Skip to content

Commit 56f024d

Browse files
fabik111pennam
authored andcommitted
add get ArduinoIoTCloud jwt
1 parent 2cb2a52 commit 56f024d

File tree

2 files changed

+40
-0
lines changed

2 files changed

+40
-0
lines changed
+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
/*
2+
This file is part of the Arduino_SecureElement library.
3+
4+
Copyright (c) 2024 Arduino SA
5+
6+
This Source Code Form is subject to the terms of the Mozilla Public
7+
License, v. 2.0. If a copy of the MPL was not distributed with this
8+
file, You can obtain one at http://mozilla.org/MPL/2.0/.
9+
*/
10+
#include "SElementArduinoCloudJWT.h"
11+
12+
constexpr char JWT_HEADER[] = "{\"alg\":\"ES256\",\"typ\":\"JWT\"}";
13+
String getAIoTCloudJWT(SecureElement &se, String issuer, uint64_t iat, uint8_t slot)
14+
{
15+
SElementJWS jws;
16+
String jwtClaim = "{\"iat\":";
17+
jwtClaim += String((uint32_t)iat);
18+
jwtClaim += ",\"iss\":\"";
19+
jwtClaim += issuer;
20+
jwtClaim += "\"}";
21+
String token = jws.sign(se, slot, JWT_HEADER, jwtClaim.c_str());
22+
return token;
23+
}

src/utility/SElementArduinoCloudJWT.h

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
/*
2+
This file is part of the Arduino_SecureElement library.
3+
4+
Copyright (c) 2024 Arduino SA
5+
6+
This Source Code Form is subject to the terms of the Mozilla Public
7+
License, v. 2.0. If a copy of the MPL was not distributed with this
8+
file, You can obtain one at http://mozilla.org/MPL/2.0/.
9+
*/
10+
11+
#ifndef SECURE_ELEMENT_AIoTCloud_JWT_H_
12+
#define SECURE_ELEMENT_AIoTCloud_JWT_H_
13+
#include "SElementJWS.h"
14+
15+
String getAIoTCloudJWT(SecureElement &se, String issuer, uint64_t iat, uint8_t slot = 1);
16+
17+
#endif

0 commit comments

Comments
 (0)