1

I want my android apps will communicate with my app engine server. I want that only authenticated user (google users) can access my EndPoints Api and to be stored in appengine using PYTHON.

Here there is an example using java appengine:
https://developers.google.com/eclipse/docs/endpoints-addauth

I want to use the User object on the server side and to save it as, and not save only the email address. As an example, my request object of the protorpc will :
MessageRequest(User user, ...)
and when the user signs in with its google account in the apps he will populate the User object (on the server) in case it is a valid google account and in case it's not a good one, he won't be able to access the API.

Thank you

1 Answer 1

1

You can do the same in Python using the endpoints library:

from google.appengine.ext import endpoints

@endpoints.api(...)
class MyApi(...):

    @endpoints.method(...)
    def my_method(self, request):
        current_user = endpoints.get_current_user()
        if current_user is None:
            # This will result in a 401
            raise endpoints.UnauthorizedException('Invalid token.')

In order to do this, you need to specify audiences= and allowed_client_ids= in either your endpoints.api decorator or endpoints.method decorator for the authenticated method.

These values are described in the Endpoints auth docs.

Sign up to request clarification or add additional context in comments.

2 Comments

In addition to this, check out a full example of a Python backend here: github.com/GoogleCloudPlatform/…
I believe the example should be raise endpoints.UnauthorizedException('Invalid token.')

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.