def get_attribute(request, name):
    """
    Return the SAML attribute stored in session.samlUserdata.
    """
    value = request.session.get('samlUserdata', {}).get(name)

    if value is not None:
        if name not in ['affiliations', 'scopedAffiliations', 'isMemberOf']:
            return value[0] if len(value) else None

    return value