Retrieve remote account information used to find local user.

def account_info(remote, resp):
    """Retrieve remote account information used to find local user."""
    resource = get_resource(remote)

    valid_identities = current_app.config.get(
        'OAUTHCLIENT_CERN_ALLOWED_IDENTITY_CLASSES',
        OAUTHCLIENT_CERN_ALLOWED_IDENTITY_CLASSES
    )
    identity_class = resource.get('IdentityClass', [None])[0]
    if identity_class is None or identity_class not in valid_identities:
        raise OAuthCERNRejectedAccountError(
            'Identity class {0} is not one of [{1}]'.format(
                identity_class, ''.join(valid_identities)), remote, resp, )

    email = resource['EmailAddress'][0]
    person_id = resource.get('PersonID', [None])
    external_id = resource.get('uidNumber', person_id)[0]
    nice = resource['CommonName'][0]
    name = resource['DisplayName'][0]

    return dict(
        user=dict(
            email=email.lower(),
            profile=dict(username=nice, full_name=name),
        ),
        external_id=external_id, external_method='cern',
        active=True
    )