简体   繁体   English

适用于PHP REST Web服务安全性的OAuth2

[英]OAuth2 for PHP REST web service security

We are working on a PHP REST web service in our web app. 我们正在Web应用程序中开发PHP REST Web服务。 Web service returns output in JSON format. Web服务以JSON格式返回输出。 Currently, anybody can view the web service's output from a URL. 当前,任何人都可以从URL查看Web服务的输出。 For example; 例如;

https://www.example.com/services/contacts/1000 https://www.example.com/services/contacts/1000

Using above URL, anybody can view contact details for contact id 1000. 使用上述URL,任何人都可以查看联系人ID 1000的联系人详细信息。

We have an authentication system in web app which uses simple email/password combination. Web应用程序中有一个身份验证系统,该系统使用简单的电子邮件/密码组合。

How can we use oauth2 for authentication for PHP REST web service? 我们如何使用oauth2进行PHP REST Web服务的身份验证? If I am correct, this has nothing to do with Google. 如果我是正确的话,这与Google无关。

Usually OAuth2 providers offers 4 authentication flows to use: 通常,OAuth2提供程序提供4种身份验证流程供使用:

  • Authorization Code, 授权码
  • Implicit, 隐式
  • Resource Owner Password Credentials and 资源所有者密码凭证和
  • Client Credentials 客户凭证

If you want more details, you can read this nice post with explanation. 如果您需要更多详细信息,可以阅读这篇不错的文章并附带说明。

The first flow - Authorization Code - is the perfect to use with web server applications (like you, using server side code with PHP). 第一个流程- 授权代码 -非常适合与Web服务器应用程序一起使用(就像您一样,将服务器端代码与PHP一起使用)。

You'll exchange data with the OAuth2 provider inside your PHP script using the cURL functions to send and read sensitive data. 您将使用cURL函数与PHP脚本内的OAuth2提供程序交换数据,以发送和读取敏感数据。

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

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