Auth0 Home Blog Docs

Auth0 Spring Security API ProviderNotFoundException when using @PreAuthorize



I am having problem using the @PreAuthorize annotation for my endpoints after following the Auth0 Spring Security for API quickstart guide. The response i get is:

 "status": 401,
 "error": "Unauthorized",

I have tried to manually set the authentication provider using the following code for my WebSecurityConfig:

    protected void configure(HttpSecurity http) throws Exception {"Configuring for Jwt token with iss {} & aud {}", issuer, audience);
        JwtWebSecurityConfigurer.forRS256(audience, issuer)
                .antMatchers(HttpMethod.GET, "/secure/**").hasAuthority("read:secure");
    protected void configure(AuthenticationManagerBuilder auth) throws Exception {
        JwkProvider jwkProvider = new JwkProviderBuilder(issuer).build();
        JwtAuthenticationProvider authenticationProvider =new JwtAuthenticationProvider(jwkProvider, issuer, audience);

And the endpoint looks like this:

    @RequestMapping(value = "/test2")
    public String test2(){

Any advice?


We are seeing similar responses, seemingly out of the blue. This is happening for us only on Native client requests. SPA client requests seem fine. This is happening on a Prod app that has been in prod for months without this issue.

@auth06 - did you ever find an answer to this?