cloudendpoints / endpoints-java

A Java framework for building RESTful APIs on Google App Engine
Apache License 2.0
32 stars 35 forks source link

PeerAuthenticator not getting called #203

Open ShaimaaSabry opened 3 years ago

ShaimaaSabry commented 3 years ago

Here is my PeerAuthenticator class:

public class TokenPeerAuthenticator implements PeerAuthenticator {
    Configuration configuration = Configuration.get();

    @Override
    public boolean authenticate(HttpServletRequest request) {
        String requiredToken = configuration.getAuthToken();

        String authorizationHeader = request.getHeader("Authorization");
        if(authorizationHeader == null) {
            return false;
        }

        String token = authorizationHeader.replace("Bearer ", "");
        if(token.equals(requiredToken)) {
            return true;
        }

        return false;
    }
}

and this my API:

@Api(name = "api", version = "v1", peerAuthenticators = TokenPeerAuthenticator.class)
public class UserAPI {
...
}

My PeerAuthenticator is not getting called. Please advice.