Hi. I am really OCaml beginner and i try to use Jwto.
Jwto(https://github.com/sporto/jwto)
I read README.md and try it.
But it does not work…
I want to simply encode and decode.
(* Encode *)
utop # let payload=[("user","koji")];;
val payload : (string * string) list = [("user", "koji")]
utop # let encoded = Jwto.encode Jwto.HS256 "secret" payload;;
val encoded : (string, string) result =
Ok
"eyJhbGciOiJIUzI1NiJ9.eyJ1c2VyIjoia29qaSJ9.iTB59lHphOi66_84L_oinHlUm95nwOJ-NJuth8MBE3c"
(* Decode *)
utop # let decoded = Jwto.decode "eyJhbGciOiJIUzI1NiJ9.eyJ1c2VyIjoia29qaSJ9.iTB59lHphOi66_84L_oinHlUm95nwOJ-NJuth8MBE3c";;
val decoded : (Jwto.t, string) result = Ok <abstr>
utop # let Ok decoded = Jwto.decode "eyJhbGciOiJIUzI1NiJ9.eyJ1c2VyIjoia29qaSJ9.iTB59lHphOi66_84L_oinHlUm95nwOJ-NJuth8MBE3c";;
val decoded : Jwto.t = <abstr>
Above codes seems to work correctly.
And “decoded”'s type is “Jwto.t”.
this is declaration of “Jwto.t” from jwto.ml
type t =
{
header: header;
payload: payload;
signature: string;
} [@@deriving show, eq]
From the my current understanding of Ocaml, i think this is a “record”.
Therefore i try to access to “signature” attribute.
But somehow this “decoded” variable does’nt seem to have the attribute…
utop # decoded.signature;;
Line 1, characters 8-17:
Error: Unbound record field signature
Why “decode” has not the attribute?
I still can’t tell if this is a Jwto problem or an OCaml problem.
OCaml version is 4.09.0, utop is 2.4.3.