Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/spring-boot/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Spring boot 包含的重定向URI无效_Spring Boot_Spring Security_Oauth 2.0_Gitlab - Fatal编程技术网

Spring boot 包含的重定向URI无效

Spring boot 包含的重定向URI无效,spring-boot,spring-security,oauth-2.0,gitlab,Spring Boot,Spring Security,Oauth 2.0,Gitlab,我正在尝试将GitLab OAuth2与Spring Boot一起使用,但我不断得到: 重定向的uri无效 我已经在GitLab中注册了该应用程序 这是我的应用程序。yml security: oauth2: client: clientId: CLIENT_ID clientSecret: CLIENT_SECRET userAuthorizationUri: https://gitlab.your-domain.com/oauth/authorize

我正在尝试将GitLab OAuth2与Spring Boot一起使用,但我不断得到:

重定向的uri无效

我已经在GitLab中注册了该应用程序

这是我的
应用程序。yml

security:
  oauth2:
   client:
     clientId: CLIENT_ID
     clientSecret: CLIENT_SECRET
     userAuthorizationUri: https://gitlab.your-domain.com/oauth/authorize
     accessTokenUri: https://gitlab.your-domain.com/oauth/token
     registered-redirect-uri:
     #- http://localhost:8080/login/oauth2/code/gitlab
     - http://localhost:8080
     tokenName: oauth_token
     authenticationScheme: query
     clientAuthenticationScheme: form
   resource:
     userInfoUri: https://gitlab.your-domain.com/api/v4/user
还有一个简单的弹簧休息课:

@springboot应用程序
@使能OAuth2SO
@RestController
公共类DemoApplication扩展了WebSecurity配置适配器{
公共静态void main(字符串[]args){
run(DemoApplication.class,args);
}
@请求映射(“/user”)
公共主要用户(主要用户){
返还本金;
}
@凌驾
受保护的无效配置(HttpSecurity http)引发异常{
http
.antMatcher(“/**”)
.授权请求()
.antMatchers(“/”、“/login**”、“/webjars/**”、“/error**”).permitAll()
.anyRequest().authenticated()
.及()
.logout()
.logoutSuccessUrl(“/”)
.permitAll();
}
}
最后是
index.html
文件:


演示
使用GitLab:
以以下身份登录:
注销
$.get(“/user”,函数(数据){
$(“#user”).html(data.userAuthentication.details.name);
$(“.unauthenticated”).hide()
$(“.authenticated”).show()
});
var logout=函数(){
$.post(“/logout”,函数(){
$(“#user”).html(“”);
$(“.unauthenticated”).show();
$(“.authenticated”).hide();
})
返回true;
}
我能够登录到GitLab,授权也成功完成,最后重定向到基本URL时:

 http://localhost:8080 
它说重定向URL无效

这是我的
POM.xml


4.0.0
org.springframework.boot
spring启动程序父级
2.1.4.1发布
com.learning
spring oauth gitlab演示应用程序
0.0.1-快照
演示
SpringBoot的演示项目
1.8
org.springframework.boot
弹簧靴起动器执行器
org.springframework.boot
SpringBootStarterWeb
org.webjars
jquery
3.4.1
org.webjars
独自创立
4.3.1
org.webjars
webjars定位核心
org.springframework.boot
弹簧启动安全
org.springframework.security.oauth.boot
spring-security-oauth2-autoconfigure
2.1.4.1发布
org.springframework.boot
弹簧起动试验
测试
org.springframework.boot
springbootmaven插件

我在Gitlab中遇到了相同的错误,我通过更改
http://localhost:5000
http://localhost:5000/

您重定向的url位于yaml中。您正在重定向到。这就是你想要的吗?/user是最终的终点,这是一个输入错误,我会编辑它。。谢谢,但即使我把它放到localhost:8080/我也面临同样的问题。在代码中还有其他问题吗?@dur我也在这里添加pom.xml,是的,我的重定向url与gitlab的相同。。但我发现spring会自动将重定向url定义为localhost:8080/login,不管我在重定向中更改了多少次_url@dur,它存在于security.oauth2.client.registered redirect uri=set下。我把它改为security.oauth2.client.pre-builded redirect uri=“redirect uri”,然后我又使用了一个属性security.oauth2.client.use current uri=false,现在它作为spring boot默认使用基本url/登录名作为重定向uri,仍然非常感谢您的支持人员,因为只有我知道问题出在哪里。