laravel9 使用laravel-passport 捕捉不到The resource owner or authorization server denied the request.错误
时间: 2024-02-23 13:57:37 浏览: 31
这个错误通常表示授权服务器拒绝了请求,可能是由于无效的凭据,过期的访问令牌或未授权的客户端等原因。出现此错误的原因有很多,可能是你的应用程序配置有误,也可能是你的 API 服务器出现了问题。
为了解决这个问题,你可以尝试以下几个步骤:
1. 检查你的应用程序配置,确保你已正确设置了 Passport 客户端 ID 和客户端秘密。
2. 检查你的访问令牌是否已过期。如果过期了,你需要重新获取访问令牌。
3. 检查你的授权服务器是否已正确配置以允许你的应用程序访问 API。你可以检查你的授权服务器日志,看看是否有任何错误或警告信息。
4. 如果你使用了自定义用户模型,请确保你已正确配置了你的模型以使用 Passport。
如果以上方法都不能解决你的问题,你可以尝试使用 Laravel Debugbar 或其他调试工具来分析你的应用程序和 API 服务器之间的通信。你也可以尝试在 Laravel 的日志文件中查找有关此错误的更多信息。
相关问题
laravel 提示Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource.
这个错误提示通常是由于跨域请求时服务器未设置 Access-Control-Allow-Origin 头部导致的。可以在服务器端的响应中添加以下代码来设置该头部:
```
header('Access-Control-Allow-Origin: *');
header('Access-Control-Allow-Methods: GET, POST, PUT, DELETE, OPTIONS');
header('Access-Control-Allow-Headers: Origin, Content-Type, X-Requested-With, Authorization');
```
其中,Access-Control-Allow-Origin 头部设置为 * 表示允许任何来源访问该资源,也可以设置为特定的域名。Access-Control-Allow-Methods 头部设置允许的请求方法,Access-Control-Allow-Headers 头部设置允许的请求头。
spring-boot-starter-oauth2-authorization-server 3.1.0 简单使用
`spring-boot-starter-oauth2-authorization-server`是Spring Boot提供的OAuth2认证服务器的Starter,可以用于构建安全的OAuth2认证授权服务器。
以下是使用`spring-boot-starter-oauth2-authorization-server`构建OAuth2认证服务器的简单步骤:
1. 添加依赖
在`pom.xml`文件中添加以下依赖:
```
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-oauth2-authorization-server</artifactId>
</dependency>
```
2. 配置认证服务器
在`application.yml`文件中添加以下配置:
```
spring:
security:
oauth2:
authorization:
server:
jwt:
signing-key: mySecretKey
client:
registration:
my-client:
client-id: my-client
client-secret: mySecret
scope:
- read
- write
redirect-uri-template: http://localhost:8080/login/oauth2/code/my-client
authorization-grant-type: authorization_code
client-name: My Client
provider:
my-authorization-server:
authorization-uri: http://localhost:8080/oauth2/authorize
token-uri: http://localhost:8080/oauth2/token
user-info-uri: http://localhost:8080/oauth2/userinfo
user-name-attribute: name
```
其中,`jwt.signing-key`是用于签名JWT的密钥,`client.registration`用于配置客户端信息,`client.provider`用于配置认证服务器信息。
3. 启动认证服务器
在Spring Boot应用程序中添加`@EnableAuthorizationServer`注解,启动OAuth2认证服务器:
```java
@SpringBootApplication
@EnableAuthorizationServer
public class OAuth2AuthorizationServerApplication {
public static void main(String[] args) {
SpringApplication.run(OAuth2AuthorizationServerApplication.class, args);
}
}
```
以上就是使用`spring-boot-starter-oauth2-authorization-server`构建OAuth2认证服务器的简单步骤。
相关推荐
![.zip](https://img-home.csdnimg.cn/images/20210720083646.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)