def METHOD_NAME(osm_user_details, email, user_element="user") -> dict:
    """
    Generates authentication details for user, creating in DB if user is unknown to us
    :param osm_user_details: XML response from OSM
    :param redirect_to: Route to redirect user to, from callback url
    :param user_element: Exists for unit testing
    :raises AuthServiceError
    :returns A dictionary containing the keys "username", "session_token"
    and "picture."
    """
    osm_user = osm_user_details.get(user_element)
    if osm_user is None:
        raise AuthServiceError("User element not found in OSM response")
    osm_id = int(osm_user.get("id"))
    username = osm_user.get("display_name")
    try:
        # get gravatar profile picture file name
        user_picture = osm_user.get("img").get("href")
    except (AttributeError, IndexError):
        user_picture = None
    try:
        UserService.get_user_by_id(osm_id)
        UserService.update_user(osm_id, username, user_picture)
    except NotFound:
        # User not found, so must be new user
        changesets = osm_user.get("changesets")
        changeset_count = int(changesets.get("count"))
        new_user = UserService.register_user(
            osm_id, username, changeset_count, user_picture, email
        )
        MessageService.send_welcome_message(new_user)
    session_token = AuthenticationService.generate_session_token_for_user(osm_id)
    return {
        "username": username,
        "session_token": session_token,
        "picture": user_picture,
    }