I'm building a custom command line tool using node. The user will need to be able to sign in and persist their session. I have done this using node and passport before for a web app using localStorage, but how should I go about storing the users JWT with a cli tool.
access_token
then even though it's a JWT you should treat it as an opaque blob because OAuth2 and OIDC clients are not the intended audience for access_token
(they're meant to pass it as-is verbatim to the remote Protected Resource).
access_token
to be anything - including non-JWT tokens, such as a short opaque "reference token" value.id_token
then you could Base64-decode it and store the decoded raw JSON in a file if you intend to use each individual Claim stored within in your client. Note that if you do store the raw JSON to a file you must use UTF-8 unless you want difficulties down the line.Each platform has a preferred location for per-user temporary data:
%LOCALAPPDATA%
(C:\Users\me\AppData\Local
), e.g. %LOCALAPPDATA%\YourCompany\YourProduct\Jwt.json
.
chmod
on the file to prevent access by other users. You could also encrypt the file with a custom password that the user must enter whenever your program runs.
~/
) and not the shared /tmp
directory. The convention on Linux for application-specific data is to use a hidden (dot-prefixed) home subdirectory, e.g. ~/.yourCompany/yourProduct
or just ~/.yourProduct
.If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With