Hi Everyone, I am just looking for some advice on the issue of storing tokens for authentication in NAV.
We currently have a requirement which means we need to store a token, in our NAV DB so it can be easily changed through a page.
The issue is this token can be quite large in size, so a 250 character size text field will not cover it.
So naturally, the next thing I looked into was storing it in a Blob field.
I have created a function which will write the input into the blob field, and a function to return this blob as a text variable.
My function returns a text variable which doesn't have a defined length. So I would assume it can handle a much larger token than I am giving it.
The issue I am seeing is that when I debug, I don't get the full length token... is this just a quirk of the debugger?
I am currently trying to test this outside of NAV, but thought I would ask the question in the mean time.
This is the code I am using to store the token, run from the page when a user changes the token
IF SubmissionToken <> OriginalToken THEN
IF CONFIRM(UpdateTokenQst) THEN BEGIN
"Submission Token".CREATEOUTSTREAM(OutStr);
BinaryWriter := BinaryWriter.BinaryWriter(OutStr);
BinaryWriter.Write(SubmissionToken);
BinaryWriter.Close;
MODIFY;
END;
and this is the function I am using to then return this as a text variable
GetTokenAsText() Token : Text
CALCFIELDS("Submission Token");
"Submission Token".CREATEINSTREAM(InStr);
BinaryReader := BinaryReader.BinaryReader(InStr);
IF NOT ISNULL(BinaryReader) THEN BEGIN
IF BinaryReader.BaseStream.Length > 0 THEN
Token := BinaryReader.ReadString;
BinaryReader.Close;
EXIT(Token);
END;
I am just wondering if there is a better way to do this?
Answers
For writting and reading text into BLOBs look into table 99008535 TempBLOB, you will find WriteAsText and ReadAsText functions in there
Dynamics NAV, MS SQL Server, Wherescape RED;
PRINCE2 Practitioner - License GR657010572SG
GDPR Certified Data Protection Officer - PECB License DPCDPO1025070-2018-03