#1 2024-01-18 07:49:09

Terinel
Member
Registered: 2024-01-18
Posts: 8

generating tokens and signing.

Is it possible to ask to show an example relevant to Mormot2 for generating tokens and signing.

function TSimpleHttpAsyncServer.GenerateToken(const UserID: Integer): RawUTF8;
var
  Claims: TJwtClaim;
  JWT: RawUTF8;
begin
// Initialize the structure for storing data in the token
  Claims.jrcJwtID := IntToStr(UserID);
  Claims.jrcExpirationTime := DateTimeToUnixTime(Now + TOKEN_EXPIRATION_TIME);

// Generate a token and sign it using a secret key
  JWT := JWTSign(TJWTAlgorithm.HS256, Claims, TOKEN_SECRET);

  Result := JWT;
end;

Last edited by Terinel (2024-01-18 07:49:55)

Offline

#2 2024-01-18 08:01:42

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 14,659
Website

Re: generating tokens and signing.

Just use the TJwtHS256 class from mormot.crypt.jwt.

Online

#3 2024-01-18 09:42:17

Terinel
Member
Registered: 2024-01-18
Posts: 8

Re: generating tokens and signing.

ab wrote:

Just use the TJwtHS256 class from mormot.crypt.jwt.

How exactly do you show a simple example

Offline

#4 2024-01-18 09:43:36

Terinel
Member
Registered: 2024-01-18
Posts: 8

Re: generating tokens and signing.

Which methods to call, in what order. What should I send there?

Offline

Board footer

Powered by FluxBB