Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / fpc-pascal / 2016-01

JSON Web Token (JWT) implementation needed

6 messages · 2 people · –

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

leledumbo

Is there anyone already implements https://tools.ietf.org/html/rfc7519? I find a Delphi implementation
(https://github.com/paolo-rossi/delphi-jose-jwt), but it uses the new Delphi RTL with System. namespace. I don't want to reinvent the wheel if possible, so if there's already one for FPC, that would be great :D

View this message in context: http://free-pascal-general.1045716.n5.nabble.com/JSON-Web-Token-JWT-implementation-needed-tp5723516.html Sent from the Free Pascal - General mailing list .

Reply by email

Michael Van Canneyt
to leledumbo
leledumbo wrote 5 lines
Is there anyone already implements https://tools.ietf.org/html/rfc7519? I find a Delphi implementation (https://github.com/paolo-rossi/delphi-jose-jwt), but it uses the new Delphi RTL with System. namespace. I don't want to reinvent the wheel if possible, so if there's already one for FPC, that would be great :D

FPC supports OAuth2. So we need JWT :)

See:

fcl-web/src/base/fpjwt.pp

If things are missing, let me know and we can add it.

Michael.

Reply by email

leledumbo
to Michael Van Canneyt: FPC supports OAuth2. So we need JWT :) See: fcl-web/src/base/fpjwt.pp If things are…

Some questions:1. How to verify the signature? My grep result in packages folder doesn't show that we have HMAC256 function.2. The following sample:{$mode objfpc}{$H+}uses fpjwt, jsonparser;const EncodedStr = 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwiYWRtaW4iOnRydWV9.TJVA95OrM7E2cBab30RMHrHDcEfxjoYZgeFONFh7HgQ';var j: TJWT;begin j := TJWT.Create; j.AsString := EncodedStr; WriteLn(j.AsString); WriteLn(EncodedStr); j.Free;end.Shows that the original EncodedStr and j.AsString differs. Is this OK or a bug?

View this message in context: http://free-pascal-general.1045716.n5.nabble.com/JSON-Web-Token-JWT-implementation-needed-tp5723516p5723521.html Sent from the Free Pascal - General mailing list .

Reply by email

Michael Van Canneyt
to leledumbo
leledumbo wrote
Some questions:1. How to verify the signature? My grep result in packages folder doesn't show that we have HMAC256 function.

I didn't implement verification, and I don't plan any. But contributions are welcome.

Show quoted text 7 lines
2. The following sample:{$mode objfpc}{$H+}uses fpjwt, jsonparser;const EncodedStr = 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwiYWRtaW4iOnRydWV9.TJVA95OrM7E2cBab30RMHrHDcEfxjoYZgeFONFh7HgQ';var j: TJWT;begin j := TJWT.Create; j.AsString := EncodedStr; WriteLn(j.AsString); WriteLn(EncodedStr); j.Free;end.Shows that the original EncodedStr and j.AsString differs. Is this OK or a bug?

That is OK.
The encoded value depends for example on the amount of whitespace in the JSON. Also, JSON doesn't specify an order of keys (property names), so the input and output keys can be in a different order, which will also result in a different encoded value.

Michael.

Reply by email

leledumbo
to Michael Van Canneyt
I didn't implement verification, and I don't plan any. But contributions are welcome.

Looks like a new entry in hmac unit + new sha256 unit would be needed. Codes are around the net but sticking to existing hash package citizens would be better for FPC future. Hope my crypto skill still stands :)

Show quoted text 8 lines
That is OK. The encoded value depends for example on the amount of whitespace in the JSON. Also, JSON doesn't specify an order of keys (property names), so the input and output keys can be in a different order, which will also result in a different encoded value.

Understood.

View this message in context: http://free-pascal-general.1045716.n5.nabble.com/JSON-Web-Token-JWT-implementation-needed-tp5723516p5723523.html Sent from the Free Pascal - General mailing list .

Reply by email