# OAuth 2.0 简介

OAuth是RESTful API中最常用的身份验证系统，不幸的是，这是一个非常复杂的话题，为了进一步阅读，Matt Frost写了一本关于OAuth和PHP的好书，题为Web Services with OAuth and PHP。

OAuth 背后简单的概念是:因为API是无状态的，所以我们不能像在基于浏览器会话一样身份认证，意思是用户登陆后他们的认证信息会被存储到session中用于后续的请求，相反，API 客户端需要调用一次身份证端，并执行某种形式的握手来证明自己，然后它会获取一个令牌，他必须在之后的请求都携带这个令牌以证明其身份(通常通过授权头)。

有几种不同类型的OAuth"发放"，这基本上意味着有几种不同的场景和交互类型可以定义认证握手。 不同的项目和不同类型的最终消费者将需要不同的“发放”。

如果你使用的是Laravel 5.1或者是5.2，有一个称为OAuth 2.0 Server for Laravel的包，可以相对容易地将基本的OAuth 2.0身份验证服务器添加到您的laravel应用程序中。

但是，如果使用的是Laravel5.3或更高版本，Passport将为你提供该软件包所提供的所有功能，以及更简单、更强大的API和接口。


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://liseen315.gitbook.io/laravel/bian-xie-apis/api-ren-zheng-he-laravel-passport/oauth-2.0-jian-jie.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
