简体   繁体   English

存储在DB api密钥中以用于第三方服务

[英]Store in DB api keys for third party service

I have a java application and I have users connecting to it with user and password. 我有一个Java应用程序,并且有用户使用用户名和密码连接到它。 I'm using amazon services for the hosting and for the rest of the stuff in the application. 我正在使用Amazon服务进行托管以及应用程序中的其他内容。

I want to make a rest call to get some data from third party service and I need the user to enter the API key for it. 我想打个电话从第三方服务获取一些数据,我需要用户为其输入API密钥。 Each user has his own API KEY. 每个用户都有自己的API KEY。

I don't want the user to enter the API KEY every time. 我不希望用户每次都输入API KEY。

I don't want to store the API KEY as is in the DB so I tried to google it but I didn't find any pro\\elegant solution. 我不想按原样将API KEY存储在数据库中,所以我尝试用Google搜索它,但没有找到任何专业的解决方案。

Do you have any idea besides encrypt and decrypt the API key using some algorithm? 除了使用某种算法对API密钥进行加密和解密之外,您还有其他想法吗?

If you want to store the API keys in a database table, then there really isn't any alternative to encrypting that data, to protect it. 如果您想将API密钥存储在数据库表中,那么除了保护数据之外,没有别的选择。 However, there is an alternative which does not involve storing the keys in a database. 但是,有另一种方法不涉及将密钥存储在数据库中。 Instead, you could use JWT user tokens. 相反,您可以使用JWT用户令牌。 Using JWT, when the user logs on, or otherwise would need to authenticate, you could prompt them to enter the API key as well. 使用JWT,当用户登录或需要进行身份验证时,您也可以提示他们输入API密钥。 Then, you would issue a token to the user which contains the API keys in the claims section. 然后,您将向用户颁发令牌,该令牌在Claims部分中包含API密钥。 Whenever the user would approach your service with the intention of calling an API, the JWT would be passed in, and the server could extract the API key. 只要用户希望通过调用API来接近您的服务,就会传递JWT,服务器可以提取API密钥。

Under the JWT approach, the API keys would only be stored with each of your users, and they would not be stored in your database or elsewhere on your system, at least not in any long term capacity. 在JWT方法下,API密钥仅与每个用户一起存储,而不会存储在数据库或系统中的其他地方,至少不会长期存储。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM