How to retrieve custom User object in GAE endpoints?

前端 未结 1 1023
悲哀的现实
悲哀的现实 2021-01-03 08:49

I\'ve just created my own custom authentication on my google app engine Java app. And it wasn\'t that much of a trouble as is the next thing I\'m trying to do.

Auth

相关标签:
1条回答
  • 2021-01-03 09:22

    AppEngine docs say the injected types are the following:

    • com.google.appengine.api.users.User
    • javax.servlet.http.HttpServletRequest
    • javax.servlet.ServletContext

    However, it doesn't mention com.google.api.server.spi.auth.common.User, but it works for sure. I just tried with AppEngine Java SDK 1.9.32. I don't know if it's a bug or feature.

    So in UserEndpoint.java, you have to import com.google.api.server.spi.auth.common.User, then you can cast it to AuthUser.

    import com.google.api.server.spi.auth.common.User;
    
    @Api(authenticators = MyAuthenticator.class)
    public class UserEndpoint {
    @ApiMethod(httpMethod = "GET")
    public final Response sth(User user)
            throws UnauthorizedException {
        EndpointUtil.throwIfNotAuthenticated(user);
    
        ((AuthUser)user).getNewToken();
    
        // ...
    }
    
    0 讨论(0)
提交回复
热议问题