You are here

janrain_capture.module in Janrain Registration 6

File

janrain_capture.module
View source
<?php

/**
 * @file
 * This module implements authentication endpoints for Janrain Capture
 *
 * @see http://www.janrain.com/products/capture
 */
require_once 'janrain_capture.api.inc';

/**
 * Implements hook_menu().
 */
function janrain_capture_menu() {
  $items['janrain_capture/oauth'] = array(
    'title' => 'Capture Oauth Receiver',
    'page callback' => 'janrain_capture_oauth',
    'access callback' => 'user_is_anonymous',
    'type' => MENU_CALLBACK,
    'file' => 'janrain_capture.pages.inc',
  );
  $items['janrain_capture/profile'] = array(
    'title' => 'Capture Profile',
    'page callback' => 'janrain_capture_profile',
    'access callback' => 'user_is_logged_in',
    'type' => MENU_CALLBACK,
    'file' => 'janrain_capture.pages.inc',
  );
  $items['janrain_capture/profile_sync'] = array(
    'title' => 'Capture Profile Receiver',
    'page callback' => 'janrain_capture_profile_sync',
    'access callback' => 'user_is_logged_in',
    'type' => MENU_CALLBACK,
    'file' => 'janrain_capture.pages.inc',
  );
  $items['janrain_capture/resend_verification_email'] = array(
    'title' => 'Capture Verification Email Resent',
    'page callback' => 'janrain_capture_resend_verification_email',
    'access callback' => TRUE,
    'type' => MENU_CALLBACK,
    'file' => 'janrain_capture.pages.inc',
  );
  $items['admin/settings/janrain_capture'] = array(
    'title' => 'Janrain Capture',
    'description' => 'Configure settings for Janrain Capture module.',
    'page callback' => 'drupal_get_form',
    'page arguments' => array(
      'janrain_capture_settings',
    ),
    'access arguments' => array(
      'administer site configuration',
    ),
    'file' => 'janrain_capture.admin.inc',
  );
  $items['janrain_capture/token_expired/%'] = array(
    'title' => 'Capture Token Expired',
    'page callback' => 'janrain_capture_token_expired',
    'access callback' => 'janrain_capture_token_expired_access',
    'access arguments' => array(
      2,
    ),
    'type' => MENU_CALLBACK,
    'file' => 'janrain_capture.pages.inc',
  );
  return $items;
}

/**
 * Access callback for janrain_capture_token_expired().
 */
function janrain_capture_token_expired_access($token) {

  // This path is for authenticated users and is protected from CSRF with a token.
  return user_is_logged_in() && $token === drupal_get_token('janrain_capture_token_expired');
}

/**
 * Returns the full URL of a specified CaptureUI screen
 *
 * @param array $options
 *   An associative array of options to use in constructing the URL
 *
 * @return string
 *   The full URL string of the Capture URL screen being requested
 */
function janrain_capture_url($options = NULL) {
  $janrain_capture_main = variable_get('janrain_capture_main', array());
  $janrain_capture_optional = variable_get('janrain_capture_optional', array());
  if (!empty($janrain_capture_main['capture_address']) && !empty($janrain_capture_main['capture_client_id'])) {
    $required = array(
      'redirect_uri' => url('janrain_capture/oauth', array(
        'absolute' => TRUE,
      )),
      'xd_receiver' => url(NULL, array(
        'absolute' => TRUE,
      )) . drupal_get_path('module', 'janrain_capture') . '/xdcomm.html',
      'client_id' => $janrain_capture_main['capture_client_id'],
    );
    if (!$options || strpos($options['action'], 'profile') !== 0) {
      if (!$options) {
        $options = array();
      }
      $defaults = array(
        'action' => 'signin',
        'recover_password_callback' => 'CAPTURE.closeRecoverPassword',
        'response_type' => 'code',
      );
    }
    else {
      $defaults = array(
        'callback' => 'CAPTURE.closeProfileEditor',
      );
    }
    $args = array_merge($required, $defaults, $options);
    $action = $args['action'];
    unset($args['action']);
    $url = 'https://' . (!empty($janrain_capture_optional['captureui_address']) ? $janrain_capture_optional['captureui_address'] : $janrain_capture_main['capture_address']) . '/oauth/' . $action . '?' . http_build_query($args, '', '&');
  }
  else {
    $url = '';
  }
  return $url;
}

Functions

Namesort descending Description
janrain_capture_menu Implements hook_menu().
janrain_capture_token_expired_access Access callback for janrain_capture_token_expired().
janrain_capture_url Returns the full URL of a specified CaptureUI screen