<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def post_authentication(self, user, request, sid, **kwargs):
 """ Things that are done after a successful authentication. :param user: :param request: :param sid: :param kwargs: :return: A dictionary with 'response_args' """


        response_info = {}

        # Do the authorization
        try:
            permission = self.endpoint_context.authz(
                user, client_id=request['client_id'])
        except ToOld as err:
            return self.error_response(
                response_info, 'access_denied',
                'Authentication to old {}'.format(err.args))
        except Exception as err:
            return self.error_response(response_info, 'access_denied',
                                       '{}'.format(err.args))
        else:
            try:
                self.endpoint_context.sdb.update(sid, permission=permission)
            except Exception as err:
                return self.error_response(response_info, 'server_error',
                                           '{}'.format(err.args))

        logger.debug("response type: %s" % request["response_type"])

        if self.endpoint_context.sdb.is_session_revoked(sid):
            return self.error_response(response_info, "access_denied",
                                       "Session is revoked")

        response_info = create_authn_response(self, request, sid)

        try:
            redirect_uri = get_uri(self.endpoint_context, request, 'redirect_uri')
        except (RedirectURIError, ParameterError) as err:
            return self.error_response(response_info,
                                       'invalid_request',
                                       '{}'.format(err.args))
        else:
            response_info['return_uri'] = redirect_uri

        # Must not use HTTP unless implicit grant type and native application
        # info = self.aresp_check(response_info['response_args'], request)
        # if isinstance(info, ResponseMessage):
        #     return info

        _cookie = new_cookie(
            self.endpoint_context, sub=user, sid=sid, state=request['state'],
            client_id=request['client_id'],
            cookie_name=self.endpoint_context.cookie_name['session'])

        # Now about the response_mode. Should not be set if it's obvious
        # from the response_type. Knows about 'query', 'fragment' and
        # 'form_post'.

        if "response_mode" in request:
            try:
                response_info = self.response_mode(request, **response_info)
            except InvalidRequest as err:
                return self.error_response(response_info,
                                           'invalid_request',
                                           '{}'.format(err.args))

        response_info['cookie'] = [_cookie]

        return response_info