REST API 认证 [英] REST API Authentication

查看:30
本文介绍了REST API 认证的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在构建一个将托管在服务器上的应用程序.我想为应用程序构建一个 API,以促进与任何平台(Web 应用程序、移动应用程序)的交互.我不明白的是,在使用 REST API 时,我们如何对用户进行身份验证.

I'm building an application which will be hosted on a server. I want to build an API for the application to facilitate interaction with from any platform (Web App, Mobile App). What I'm not understanding is that when using the REST API, how do we authenticate the user.

例如,当用户登录后想要创建论坛主题时.我如何知道用户已经登录?

For example, when a user has logged in and then wants to create a forum topic. How will I know that the user is already logged in?

推荐答案

您可以使用 HTTP 基本身份验证或摘要式身份验证.您可以在其上使用 SSL 安全地对用户进行身份验证,但是,它会稍微降低 API 的速度.

You can use HTTP Basic or Digest Authentication. You can securely authenticate users using SSL on the top of it, however, it slows down the API a little bit.

  • 基本身份验证 - 对用户名和密码使用 Base64 编码
  • 摘要式身份验证 - 在通过网络发送之前对用户名和密码进行哈希处理.

OAuth 是最好的.oAuth 的优点是可撤销或可过期的令牌.实现方法参考以下:来自评论的工作链接:https://www.ida.liu.se/~TDP024/labs/hmacarticle.pdf

OAuth is the best it can get. The advantages oAuth gives is a revokable or expirable token. Refer following on how to implement: Working Link from comments: https://www.ida.liu.se/~TDP024/labs/hmacarticle.pdf

这篇关于REST API 认证的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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