0

I would like to add OAuth to my endpoints backend. As the "Hello Endpoints Code Walk Through" points out, it is enough to have the following:

@ApiMethod(name = "greetings.authed", path = "hellogreeting/authed")
    public HelloGreeting authedGreeting(User user) {
    HelloGreeting response = new HelloGreeting("hello " + user.getEmail());
    return response;
}

But what if the method type is Post and it contains a body? I cannot pass User and the request body to the method.

How can I use OAuth with Post type methods that contain a request body?

RSai
  • 51
  • 6

2 Answers2

2

Just like this:

@ApiMethod(name = "greetings.authed", path = "hellogreeting/authed")
    public HelloGreeting authedGreeting(User user, MyObject myObject) {
    HelloGreeting response = new HelloGreeting("hello " + user.getEmail());
    return response;
}

User is an injected type that Google App Engine will inject for you as saiyr pointed out.

If you did want to pass more than one object outside those scopes you would need to create a wrapper class that has those two objects are properties with getters/setters.

Micro
  • 10,303
  • 14
  • 82
  • 120
  • Thanks I just found out that AndroidStudio's lint checker marks it as an error but it just compiles fine. Looks like a known bug. – RSai Aug 26 '16 at 13:37
1

The two allowed User objects spi.auth.common.User and appengine.api.users.User do not count as resource parameters, as they are injected at runtime. You're free to add a resource to a method that has a User parameter on it.

saiyr
  • 2,575
  • 1
  • 11
  • 13