移动后端 API 密钥的安全性 [英] Security of Mobile Backend API key

查看:25
本文介绍了移动后端 API 密钥的安全性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

假设我正在开发一个调用 API 服务器的移动应用程序.API 服务器由 API 密钥保护.

Suppose I am developing a mobile application that makes calls to an API server. The API server is secured by an API Key.

我无法在移动应用程序中对 API 密钥进行硬编码,因为它可能被盗.

I cannot hard-code the API Key inside the mobile application because it can be stolen.

如何保护 API 密钥?

How can I protect the API key?

推荐答案

这个问题通常是如何解决的?

How is that problem usually solved?

(听起来您试图保护的 API 密钥是用于您不拥有的 API 服务的.)

(It sounds like the API-key you are trying to protect is for an API service that you don't own.)

一种方法是使用身份验证服务器.私有 API 密钥保存在身份验证服务器上,仅在有效登录后共享.

One approach is by using an authentication server. The private API-key is kept on the authentication server and only shared after a valid login.

那么这是如何工作的?

  • 移动客户端上的用户输入登录信息密码
  • 这些凭据会被发送到验证服务器中进行验证
  • 如果登录有效,API 密钥将发送到移动客户端

在架构上,您需要一个单独的身份验证服务器,这会给您留下 2 个不同的服务器:

Architecturally, you would need a separate authentication server which would leave you with 2 different servers:

  1. 一些需要私有 API 密钥才能使用的 API 密钥服务器

  1. Some API-key server that you need a private API-key to use

身份验证服务器(用于验证用户登录和交换私有 API 密钥)

Authentication server (used to verify user login and exchange private API-keys)

第二种方法是使用直通服务器.在这种方法中永远不会共享私有 API 密钥.可以在 pass-thru 服务器上添加身份验证,但不是必需的.

A second approach is to use a pass through server. The private API-key is never shared in this approach. It is possible to add authentication onto the pass-thru server, but not required.

那么这是如何工作的?

  • 移动用户联系传递服务器以获取来自 API 的数据
  • 传递服务器进行 API 调用(使用存储的私有 API 密钥)
  • API 服务器以数据响应传递服务器
  • 传递服务器将 API 响应转发到移动应用

在这种情况下,您拥有 pass-thru 服务器,因此您永远不需要共享您的 API 密钥,并且用户身份验证是可选的.

In this case, you own the pass-thru server so you never need to share your API keys and user authentication is optional.

这篇关于移动后端 API 密钥的安全性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆