Standalone Spring OAuth2 JWT Authorization Server + CORS

前端 未结 6 1331
长发绾君心
长发绾君心 2020-11-28 04:01

So I have the following Authorization Server condensed from this example from Dave Syer

@SpringBootApplication
publi         


        
6条回答
  •  清歌不尽
    2020-11-28 04:32

    Using Spring Boot 2 here.

    I had to do this in my AuthorizationServerConfigurerAdapter

    @Override
    public void configure(AuthorizationServerEndpointsConfigurer endpoints) {
    
        Map corsConfigMap = new HashMap<>();
        CorsConfiguration config = new CorsConfiguration();
        config.setAllowCredentials(true);
        //TODO: Make configurable
        config.setAllowedOrigins(Collections.singletonList("*"));
        config.setAllowedMethods(Collections.singletonList("*"));
        config.setAllowedHeaders(Collections.singletonList("*"));
        corsConfigMap.put("/oauth/token", config);
        endpoints.getFrameworkEndpointHandlerMapping()
                .setCorsConfigurations(corsConfigMap);
    
        //additional settings...
    }
    

提交回复
热议问题