'Authenticate the user based on an OpenID response.'

def authenticate(self, **kwargs):

    openid_response = kwargs.get('openid_response')
    if (openid_response is None):
        return None
    if (openid_response.status != SUCCESS):
        return None
    user = None
    try:
        user_openid = UserOpenID.objects.get(claimed_id__exact=openid_response.identity_url)
    except UserOpenID.DoesNotExist:
        if getattr(settings, 'OPENID_CREATE_USERS', False):
            user = self.create_user_from_openid(openid_response)
    else:
        user = user_openid.user
    if (user is None):
        return None
    if getattr(settings, 'OPENID_UPDATE_DETAILS_FROM_SREG', False):
        details = self._extract_user_details(openid_response)
        self.update_user_details(user, details, openid_response)
    if getattr(settings, 'OPENID_PHYSICAL_MULTIFACTOR_REQUIRED', False):
        pape_response = pape.Response.fromSuccessResponse(openid_response)
        if ((pape_response is None) or (pape.AUTH_MULTI_FACTOR_PHYSICAL not in pape_response.auth_policies)):
            raise MissingPhysicalMultiFactor()
    teams_response = teams.TeamsResponse.fromSuccessResponse(openid_response)
    if teams_response:
        self.update_groups_from_teams(user, teams_response)
        self.update_staff_status_from_teams(user, teams_response)
    return user
