I'm using this module in conjunction with Token Authentication (tokenauth) to provide some semblance of security to feeds.

Unfortunately, this module manually generates the ical links in a theme function, rather than allowing Drupal to know about it. (I'm guessing because of the webcal:// format.)

In order to add the user's token to the end of the URL you can override this theme function using MYTHEME_date_ical_icon($vars).

<?php
/**
 * Alternate theme function to include tokenauth support.
 */
function MYTHEME_date_ical_icon($variables) {
  if (empty($variables['tooltip'])) {
    $variables['tooltip'] = t('Add this event to my calendar');
  }
  $variables['path'] = drupal_get_path('module', 'date_ical') . '/images/ical-feed-icon-34x14.png';
  $variables['alt'] = $variables['title'] = $variables['tooltip'];
  $token = tokenauth_get_token();
  if ($image = theme('image', $variables)) {
    return "<a href='{$variables['url']}?token={$token}' class='ical-icon'>$image</a>";
  }
  else {
    return "<a href='{$variables['url']}?token={$token}' class='ical-icon'>{$variables['tooltip']}</a>";
  }
}
?>

Comments

coredumperror’s picture

Do you have any suggestions for how I could improve Date iCal to make it more compatible by default? You mention "this module manually generates the ical links in a theme function, rather than allowing Drupal to know about it." How would you suggest that I let Drupal know about it?

In fact, the webcal:// mechanism is handled in the Views Style plugin (the attach_to() function), rather than in that theme function. The theme function is a holdover from the previous version of Date iCal, before I took over. I'd be more than happy to completely refactor that functionality for better intermodule compatibility, but I don't really know what I should do.

jessehs’s picture

The tokenauth module implements hook_url_outbound_alter, and appends the current user's token to any path run through url()
that also passes tokenauth's allowed pages filter. If you use the Drupal url() function to generate the URL, I think that would do it.

coredumperror’s picture

Huh, that's odd. Date iCal already uses the url() function (line 27 in date_ical_plugin_style_ical_feed.inc), so tokenauth's hook_url_outbound_alter() should be getting invoked.

Looking at tokenauth's code, I see that it runs tokenauth_allowed_pages($original_path) to check if it should do anything. Maybe the URL for the feed isn't "allowed"? Unless you explicitly tell tokenauth to allow your feed URLs, with all necessary wildcards, it won't add the token.

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.

jhedstrom’s picture

For others finding this issue looking to add tokenauth tokens to ical feeds, I accomplished this using the following:


/**
 * Implements hook_views_pre_build().
 *
 * Append a tokenauth token to ical feeds if user is logged in.
 */
function mymodule_views_pre_build(&$view) {
  if ($view->name == 'event_calendar' && !user_is_anonymous()) {
    $path = $view->display['feed_1']->handler->options['path'];
    if (strpos($path, 'token') === FALSE) {
      $view->display['feed_1']->handler->options['path'] .= '?token=' . tokenauth_get_token();
    }
  }
}

rbrownell’s picture

Category: Support request » Feature request
Issue summary: View changes
Status: Closed (fixed) » Active

Re opening this. I believe that this is an essential component that should probably be integrated at some point.

coredumperror’s picture

I'm not entirely certain what Date iCal can even do differently here. It already uses the url() function to generate that link, so Token Authentication should be adding the token as long as it's configured properly.

Do you have a specific request regarding how Date iCal should behave differently?

rbrownell’s picture

Yes. This functionality requires modification to a theme's template.php file. To make this more user friendly for non-developers this functionality should be implemented into Date iCal.

coredumperror’s picture

> This functionality requires modification to a theme's template.php file

What modification are you referring to?

rbrownell’s picture

@coredumperror The functionality that is indicated in the summary of this issue. That is, we are looking for an option that would enable token authentication support without the need to add extra code to our template.php files.

coredumperror’s picture

As I stated in comment #3, this is not Date iCal's fault:

Looking at tokenauth's code, I see that it runs tokenauth_allowed_pages($original_path) to check if it should do anything. Maybe the URL for the feed isn't "allowed"? Unless you explicitly tell tokenauth to allow your feed URLs, with all necessary wildcards, it won't add the token.

You need to configure tokenauth to "allow" your feeds' URLs, or it will not inject that token into the URLs that Date iCal generates.

coredumperror’s picture

Status: Active » Closed (works as designed)

This works as designed, so I'm closing this issue.