你好,我现在用Angluar+Spring Boot来建一个网站,我用okta单页App来做认证。在我的前台,我可以登录和重定向回来,我还添加了以下功能 Authorization: Bearer {Token}
当我调用后端api时,头文件中会出现错误。
所以问题是当我安装okta-spring-boot-starter(1.4.0)的时候,会出现这个错误,我想可能是我没有设置okta的配置。
Bearer error="invalid_token", error_description="An error occurred while attempting to decode the Jwt: Invalid token", error_uri="https://tools.ietf.org/html/rfc6750#section-3.1"
我想这可能是由于我没有设置okta的配置,然后我在application.yml文件中添加了okta的属性,并使用WebSecurityConfigurer。
spring:
profiles:
active: "dev"
main:
banner-mode: "off"
okta.oauth2:
client-id: 0oaebbeiaBCbFFtDU4x6
issuer: https://dev-574831.okta.com
audience: https://dev-574831.okta.com
然后我在application.yml文件中添加了okta的属性,并参照WebSecurityConfigurerAdapter来使用: https:/github.comoktasamples-java-springblobmasterresource-serversrcmainjavacomoktaspringexampleResourceServerExampleApplication.java。
import com.okta.spring.boot.oauth.Okta;
import org.springframework.context.annotation.Configuration;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
@Configuration
@EnableWebSecurity
public class OktaOAuth2WebSecurityConfig extends WebSecurityConfigurerAdapter {
@Override
protected void configure(HttpSecurity http) throws Exception {
http.authorizeRequests()
.antMatchers("/userinfo").permitAll()
.antMatchers("/health").permitAll()
.anyRequest().authenticated()
.and()
.oauth2ResourceServer().jwt();
http.cors();
Okta.configureResourceServer401ResponseBody(http);
}
}
我还是得到了同样的错误信息。
是我错过了什么,还是我的项目无法识别okta配置?
试试这个。
okta:
oauth2:
client-id: 0oaebbeiaBCbFFtDU4x6
issuer: https://dev-574831.okta.com/oauth2/default