Storing API tokens in cookie storage or local storage

I would like to be able to access the browsers cookies (or local storage or some equivalent persistent state) to store user’s API tokens so they don’t need to login to a service every time they load a panel app.

It looks like you provide access to cookies via pn.state.cookies, but as far as I can tell this is just a single session state that is stored in memory and not on disk.

Is there a way to do what I am looking for?

1 Like

Yes. You will need to run some javascript.

You can run javascripts very simply inside pn.pane.HTML('<script> your js here </script>') or via for example a ReactiveHTML class.

I am working on some github oauth that sets cookies here panel-sharing/ at 394f550c4a7f59dcb43631ee5147e9b239c1db36 · awesome-panel/panel-sharing · GitHub

Cool, thanks for the link!

I am curious, what is the point of the cookies attribute at all? It seems disingenuous to suggest it allows access cookies stored in the browser, since that doesn’t seem true

1 Like

Hi @sammaphey

With pn.state.cookies you will be able to read the cookies that are set when the client/ browser makes the initial request. It will not enable you to read the current cookies (if they changed) or to set them.

Why the functionality is limited, I don’t know. But its probably because no one besides us have ever needed it or made a Feature Request. Feel free to make a feature request or even better contribute an improvement.