'Processing the request is a multi-step process, as follows:
Step 1. The safe_cookie_data is parsed and verified from the
session cookie.
Step 2. The session_id is retrieved from the safe_cookie_data
and stored in place of the session cookie value, to be used by
Django\'s Session middleware.
Step 3. Call Django\'s Session Middleware to find the session
corresponding to the session_id and to set the session in the
request.
Step 4. Once the session is retrieved, verify that the user
bound in the safe_cookie_data matches the user attached to the
server\'s session information.
Step 5. If all is successful, the now verified user_id is stored
separately in the request object so it is available for another
final verification before sending the response (in
process_response).'

def process_request(self, request):

    cookie_data_string = request.COOKIES.get(settings.SESSION_COOKIE_NAME)
    if cookie_data_string:
        try:
            safe_cookie_data = SafeCookieData.parse(cookie_data_string)
        except SafeCookieError:
            return self._on_user_authentication_failed(request)
        else:
            request.COOKIES[settings.SESSION_COOKIE_NAME] = safe_cookie_data.session_id
    process_request_response = super(SafeSessionMiddleware, self).process_request(request)
    if process_request_response:
        return process_request_response
    if (cookie_data_string and request.session.get(SESSION_KEY)):
        user_id = self.get_user_id_from_session(request)
        if safe_cookie_data.verify(user_id):
            request.safe_cookie_verified_user_id = user_id
        else:
            return self._on_user_authentication_failed(request)
