JWT Delphi Client

From sgcWebSockets 4.4.8 JWT is supported on Client components like WebSocket Client and HTTP/2 Client.

The TsgcHTTP_JWT_Client component allows to encode and sign JWT Tokens, attached to a WebSocket Client or HTTP/2 client, the token will be sent automatically as an Authorization Bearer Token Header.


 You can configure the JWT values in the JWTOptions properties, there are 2 main properties: Header and Payload, just set the values for every required property.

If the Signature is encrypted using a Private Key (RS and ES algorithms), set the value in the PrivateKey property of the Algorithm.

If the Signature is encrypted using a Secret (HS algorithms), set the value in the Secret property of the Algorithm.

Custom Headers 

The Header and Payload properties contains the most common headers used to generate a JWT, but you can add more headers calling the method AddKeyValue and passing the Key and Value as parameters.

Example: if you want add a new record in the JWT Header with your name, use the following method

Header.AddKeyValue('name', 'John Smith');

After configuring the properties, to generate the JWT, just call the method Sign and will return the value of the JWT.

WebSocket Client and JWT 

TsgcWebSocketClient allows the use of JWT when connecting to WebSocket servers, just create a new JWT client and assign to Authentication.Token.JWT property.

oClient := TsgcWebSocketClient.Create(nil);
oClient.URL := 'ws://echo.websocket.org';

oJWT := TsgcHTTP_JWT_Client.Create(nil);
oJWT.Header.alg := jwtRSA256;
oJWT.Payload.sub := '1234567890';
oJWT.Payload.iat := 1516239022;

oClient.Authentication.Enabled := True;
oClient.Authentication.URL.Enabled := False;
oClient.Authentication.Token.Enabled := True;
oClient.Authentication.Token.JWT := oJWT;
oClient.Active := True; 
File Name: sgcJWT
File Size: 3.5 mb
Download File
Stay Informed

When you subscribe to the blog, we will send you an e-mail when there are new updates on the site so you wouldn't miss them.

JWT Delphi Server
WebSocket Send File .NET

Related Posts