Best way to save authentication token?

折月煮酒 提交于 2019-12-06 02:01:50

I would use the Windows Data Protection There are numerous examples around on how to use it from C#. It uses a user specific key to encrypt the data. Only the user themselves can decrypt it. Also be sure to secure the data during transmission between the server and the client.

Create a settings file for your project in the project properties, add a AuthToken property to the known settings (probably at the user level), then use:

Properties.Settings.Default.AuthToken = userAuthToken;

If you think they'll want it hidden, encrypt or encode the userAuthToken so it is less obvious.

You can verify if the api is used under asp.net or windows environment ( it's enough to check if Request is null) and on the first case use a cookie, on the latter save it on a registry key.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!