Redirect 使用JAX-RS客户端API临时重定向
我正在尝试将当前项目与外部身份验证API集成,现在我的目标是重定向到外部url:Redirect 使用JAX-RS客户端API临时重定向,redirect,spring-security,jax-rs,http-redirect,Redirect,Spring Security,Jax Rs,Http Redirect,我正在尝试将当前项目与外部身份验证API集成,现在我的目标是重定向到外部url: https://auth.mercadolivre.com.br/authorization?response_type=code&client_id=$APP_ID 在自动化过程发生的地方,之后会重定向回我的应用程序,url如下: http://YOUR_REDIRECT_URI?code=SERVER_GENERATED_AUTHORIZATION_CODE 我需要在内部存储此code变量的位置 到
https://auth.mercadolivre.com.br/authorization?response_type=code&client_id=$APP_ID
在自动化过程发生的地方,之后会重定向回我的应用程序,url如下:
http://YOUR_REDIRECT_URI?code=SERVER_GENERATED_AUTHORIZATION_CODE
我需要在内部存储此code
变量的位置
到目前为止,我根据可用的示例得到了这段代码,并且:
但是,尽管应用程序到达了目标,但html并没有在浏览器中打开,而是转储到控制台上并发出错误(类似于转储到控制台上的代码中的无效字符)
我只是通过上面的方法将用户重定向到授权页面(第一个链接),当流程结束时,执行其余代码,存储返回的值以备将来使用
作为参考,此代码是从my spring安全层中的AuthenticationManager调用的。到目前为止,我得到的实施:
@Configuration
@EnableWebSecurity
public class Security extends WebSecurityConfigurerAdapter {
@Bean
@Override
public AuthenticationManager authenticationManagerBean() throws Exception {
return new AuthManager();
}
@Override
public void configure(HttpSecurity http) throws Exception {
...
}
@Override
public void configure(WebSecurity web) throws Exception {
...
}
public class AuthManager implements AuthenticationManager {
@Override
public Authentication authenticate(Authentication authentication) throws AuthenticationException {
MercadoLivre mercadoLivre = new MercadoLivre();
try {
mercadoLivre.getAccessToken();
UserResponse data = (UserResponse) mercadoLivre.GET("/users/"+mercadoLivre.getUserId().toString());
return new AuthResponse(data);
} catch (Exception e) {
e.printStackTrace();
return null;
}
}
}
public class AuthResponse implements Authentication {
...
}
}
该方法是从内部调用的getAccessToken()
@Configuration
@EnableWebSecurity
public class Security extends WebSecurityConfigurerAdapter {
@Bean
@Override
public AuthenticationManager authenticationManagerBean() throws Exception {
return new AuthManager();
}
@Override
public void configure(HttpSecurity http) throws Exception {
...
}
@Override
public void configure(WebSecurity web) throws Exception {
...
}
public class AuthManager implements AuthenticationManager {
@Override
public Authentication authenticate(Authentication authentication) throws AuthenticationException {
MercadoLivre mercadoLivre = new MercadoLivre();
try {
mercadoLivre.getAccessToken();
UserResponse data = (UserResponse) mercadoLivre.GET("/users/"+mercadoLivre.getUserId().toString());
return new AuthResponse(data);
} catch (Exception e) {
e.printStackTrace();
return null;
}
}
}
public class AuthResponse implements Authentication {
...
}
}