我有2个正在运行的应用程序,一个是资源服务器,其中有我需要身份验证才能查看文本的信息。然后,我有提供令牌的授权服务器。现在,我可以使用邮递员或失眠者,添加auth_url,token_url,client_id,client_secret,然后我会得到令牌。我将令牌添加到标头中,并使用标头向资源服务器执行get请求,并且它工作得很好。
现在我不知道如何直接从资源服务器实现重定向。就像我去
本地主机:9000 / home
我想重定向到:
本地主机:9001 /登录
我使用内存用户登录的位置,然后将我重定向回localhost:9000 / home,然后看到消息。
实现用户访问localhost:9000 / home上的信息的最佳方法是什么?您转到localhost:9000 / home,然后转到localhost:9001上的授权服务器,并使用用户名和密码登录。批准授予,它使您返回到localhost:9000 / home,然后您可以看到文本,该文本以前受到保护,因为您没有令牌来访问它。
ResourceServer.java
@SpringBootApplication
@RestController
@EnableResourceServer
@EnableOAuth2Client
public class SampleResourceApplication extends ResourceServerConfigurerAdapter {
@Override
public void configure(HttpSecurity http) throws Exception {
http.antMatcher("/**")
.authorizeRequests()
.antMatchers("/", "/login**").hasRole("user")
.anyRequest().authenticated();
}
@Bean
public RequestContextListener requestContextListener() {
return new RequestContextListener();
}
public static void main(String[] args) {
SpringApplication.run(SampleResourceApplication.class, args);
}
@RequestMapping("/home")
public String home() {
return "this is home";
}
}
Run Code Online (Sandbox Code Playgroud)
和我的财产看起来像:
server:
port: 900
security:
oauth2:
client:
client-id: …Run Code Online (Sandbox Code Playgroud)