admin管理员组文章数量:1122846
I have an easy Spring Boot API Rest. It authenticates with Google Oauth 2.0. To check de API Rest, I´m using Postman.
When I try it on local, everything with Postman works perfectly.
When I try it on production, Postman gives me one error:
Bearer error="invalid_token", error_description="An error occurred while attempting to decode the Jwt: Malformed token", error_uri=".1"
I´ve followed a few tutorials about configurating Google Cloud and Postman for OAuth 2.0. I think that must be correct.
Maybe the problem will be with Java Backend?
package com.test.config;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.security.config.Customizer;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
import org.springframework.security.oauth2.client.registration.ClientRegistrationRepository;
import org.springframework.security.oauth2.client.AuthorizedClientServiceOAuth2AuthorizedClientManager;
import org.springframework.security.oauth2.client.OAuth2AuthorizedClientService;
import org.springframework.security.oauth2.jwt.JwtDecoder;
import org.springframework.security.oauth2.jwt.NimbusJwtDecoder;
import org.springframework.security.web.SecurityFilterChain;
import org.springframework.core.env.Environment;
@Configuration
@EnableWebSecurity
public class SecurityConfig {
@Bean
public SecurityFilterChain securityFilterChain(HttpSecurity http, ClientRegistrationRepository clientRegistrationRepository, OAuth2AuthorizedClientService authorizedClientService) throws Exception {
http.authorizeHttpRequests(authorizeRequests -> authorizeRequests
.requestMatchers("/login").permitAll()
.requestMatchers("/api/**").authenticated()
.requestMatchers("/swagger-ui/**", "/v3/api-docs/**", "/swagger-ui.html").permitAll()
.anyRequest().authenticated())
.csrf(csrf -> csrf.disable())
.oauth2Login(oauth2Login -> oauth2Login
.clientRegistrationRepository(clientRegistrationRepository)
.authorizedClientService(authorizedClientService)
.redirectionEndpoint(redirectionEndpoint -> redirectionEndpoint
.baseUri("/login/oauth2/code/google")))
.oauth2ResourceServer(oauth2ResourceServer -> oauth2ResourceServer
.jwt(Customizer.withDefaults()));
return http.build();
}
@Bean
public JwtDecoder jwtDecoder(Environment environment) {
String jwkSetUri = environment.getProperty("spring.security.oauth2.resourceserver.jwt.jwk-set-uri");
return NimbusJwtDecoder.withJwkSetUri(jwkSetUri).build();
}
@Bean
public AuthorizedClientServiceOAuth2AuthorizedClientManager authorizedClientManager(ClientRegistrationRepository clientRegistrationRepository, OAuth2AuthorizedClientService authorizedClientService) {
return new AuthorizedClientServiceOAuth2AuthorizedClientManager(clientRegistrationRepository, authorizedClientService);
}
}
Any idea what´s wrong? Thanks!!
本文标签: Spring Boot with Google OAuth 2 doesn180t work with PostmanStack Overflow
版权声明:本文标题:Spring Boot with Google OAuth 2 doesn´t work with Postman - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1736283842a1927100.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论