1.. _auth.i18n:
2
3Authentication with webapp2
4===========================
5
6Login with forms
7----------------
8
9Login with sessions
10-------------------
11
12Login with tokens
13-----------------
14
15
16Custom User model
17-----------------
18:mod:`webapp2_extras.appengine.auth.models` provides a default ``User`` model
19to be used on App Engine, but it can be replaced by any custom model that
20implements the required interface. This means that :mod:`webapp2_extras.auth`
21can be used with any model you wish -- even non-App Engine models which use,
22let's say, ``SQLAlchemy`` or other abstraction layers.
23
24The required interface that a custom user model must implement consists of
25only five methods::
26
27    class User(object):
28
29        def get_id(self):
30            """Returns this user's unique ID, which can be an integer or string."""
31
32        @classmethod
33        def get_by_auth_token(cls, user_id, token):
34            """Returns a user object based on a user ID and token.
35
36            :param user_id:
37                The user_id of the requesting user.
38            :param token:
39                The token string to be verified.
40            :returns:
41                A tuple ``(User, timestamp)``, with a user object and
42                the token timestamp, or ``(None, None)`` if both were not found.
43            """
44
45        @classmethod
46        def get_by_auth_password(cls, auth_id, password):
47            """Returns a user object, validating password.
48
49            :param auth_id:
50                Authentication id.
51            :param password:
52                Password to be checked.
53            :returns:
54                A user object, if found and password matches.
55            :raises:
56                ``auth.InvalidAuthIdError`` or ``auth.InvalidPasswordError``.
57            """
58
59        @classmethod
60        def create_auth_token(cls, user_id):
61            """Creates a new authorization token for a given user ID.
62
63            :param user_id:
64                User unique ID.
65            :returns:
66                A string with the authorization token.
67            """
68
69        @classmethod
70        def delete_auth_token(cls, user_id, token):
71            """Deletes a given authorization token.
72
73            :param user_id:
74                User unique ID.
75            :param token:
76                A string with the authorization token.
77            """
78
79Additionally, all values configured for ``user_attributes``, if any, must
80be provided by the user object as attributes. These values are stored in the
81session, providing a nice way to cache commonly used user information.
82