English 中文(简体)
Can 我在春布特·奥乌特2客户的最初要求下,具体说明伐木后的间接地址?
原标题:Can I specify the redirect address after logging in on the initial request in Spring Boot OAuth2 client?

I m 制作一个网络相片器,在社会标识中要求的直线地址在网络环境与信号环境之间有所不同。 我愿像社会标志要求那样,确定最后的再方向。

http:// localhost:80/auth/oauth2/authorize/google?redirect_uri=bar://

是否有办法解决这一问题?

I wanted to intercept the first request in the OAuth2 filter and pass the redirect_uri to the final successHandler, but I couldn t find a way to do it.

问题回答

不同的直接地址按不同的日志客户返回?

    @Bean
    public SecurityFilterChain filterChain(HttpSecurity http,ClientRegistrationRepository clientRegistrationRepository ) throws Exception {
        return http
                .csrf(AbstractHttpConfigurer::disable)
                .oauth2Login(c -> c.authorizationEndpoint(cc->cc.authorizationRequestResolver(new CustomOAuth2AuthorizationRequestResolver(clientRegistrationRepository))))
                .authorizeHttpRequests(c -> c.anyRequest().authenticated())
                .build();
    }

    static class CustomOAuth2AuthorizationRequestResolver implements OAuth2AuthorizationRequestResolver{
        private final OAuth2AuthorizationRequestResolver resolver;

        public CustomOAuth2AuthorizationRequestResolver(ClientRegistrationRepository clientRegistrationRepository) {
            DefaultOAuth2AuthorizationRequestResolver resolver =
                    new DefaultOAuth2AuthorizationRequestResolver(clientRegistrationRepository, OAuth2AuthorizationRequestRedirectFilter.DEFAULT_AUTHORIZATION_REQUEST_BASE_URI);
            resolver.setAuthorizationRequestCustomizer(builder -> {
                if (isWebLogin()) {
                    builder.redirectUri("foo://");
                }else if (isAppLogin()) {
                    builder.redirectUri("bar://");
                }
            });
            this.resolver = resolver;
        }

         
        @Override
        public OAuth2AuthorizationRequest resolve(HttpServletRequest request) {
            return resolver.resolve(request);
        }

        @Override
        public OAuth2AuthorizationRequest resolve(HttpServletRequest request, String clientRegistrationId) {
            return resolver.resolve(request,clientRegistrationId);
        }
    }




相关问题
Spring Security Encrypt MD5

I have a java web application using spring framework and spring security for its login. In my database I have my passwords encrypted to MD5 before being saved. I added in my application-config.xml ...

Grails security [closed]

Which is the best security solution for grails among acegi, jsecurity and Stark security?

Rewrite spring-security redirect URLs

I m trying to get Tuckey UrlRewriteFilter to tidy up URLs for my webapp. One problem I ve got is that when spring-security notices that an anonymous user is trying to access a protected resource it ...

Spring Security Custom freemarker form

I m currently working on a project were we use freemarker as a template language. Instead of using the defualt login form I have created a custom controller and a custom freemarker view which goes ...

Spring Security - Different Filter Entry Points based on Role

I m developing a webapp which allows for two types for users - User and Admin. There s are two parts of the site - the User side, and the Admin side. I m using Spring Security to secure both sites ...

热门标签