Ignore:
Timestamp:
Jan 11, 2014, 1:27:14 AM (10 years ago)
Author:
mistic100
Message:

add Persona authentification

File:
1 edited

Legend:

Unmodified
Added
Removed
  • extensions/oAuth/include/functions.inc.php

    r26604 r26605  
    2525function oauth_assign_template_vars($u_redirect=null)
    2626{
    27   global $template, $conf, $hybridauth_conf;
     27  global $template, $conf, $hybridauth_conf, $user;
    2828 
    2929  $conf['oauth']['include_common_template'] = true;
     
    3131  if ($template->get_template_vars('OAUTH') == null)
    3232  {
     33    if (!empty($user['oauth_id']))
     34    {
     35      list($provider, $identifier) = explode('---', $user['oauth_id'], 2);
     36      if ($provider == 'Persona')
     37      {
     38        $persona_email = $identifier;
     39      }
     40    }
     41   
    3342    $template->assign('OAUTH', array(
    3443      'conf' => $conf['oauth'],
    3544      'u_login' => get_root_url() . OAUTH_PATH . 'auth.php?provider=',
    3645      'providers' => $hybridauth_conf['providers'],
     46      'persona_email' => @$persona_email,
    3747      ));
    3848    $template->assign(array(
     
    7080  }
    7181}
     82
     83// http://www.sitepoint.com/authenticate-users-with-mozilla-persona/
     84function persona_verify()
     85{
     86  $url = 'https://verifier.login.persona.org/verify';
     87
     88  $assert = filter_input(
     89    INPUT_POST,
     90    'assertion',
     91    FILTER_UNSAFE_RAW,
     92    FILTER_FLAG_STRIP_LOW|FILTER_FLAG_STRIP_HIGH
     93    );
     94
     95  $scheme = 'http';
     96  if ( (!empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] !== 'off') || $_SERVER['SERVER_PORT'] == 443 )
     97  {
     98    $scheme = 'https';
     99  }
     100  $audience = sprintf(
     101    '%s://%s:%s',
     102    $scheme,
     103    $_SERVER['HTTP_HOST'],
     104    $_SERVER['SERVER_PORT']
     105    );
     106
     107  $params = 'assertion=' . urlencode($assert) . '&audience=' . urlencode($audience);
     108
     109  $options = array(
     110    CURLOPT_URL => $url,
     111    CURLOPT_RETURNTRANSFER => true,
     112    CURLOPT_POST => true,
     113    CURLOPT_POSTFIELDS => $params,
     114    CURLOPT_SSL_VERIFYPEER => true,
     115    CURLOPT_SSL_VERIFYHOST => 2,
     116    );
     117
     118  $ch = curl_init();
     119  curl_setopt_array($ch, $options);
     120  $result = curl_exec($ch);
     121  curl_close($ch);
     122 
     123  if ($result === false)
     124  {
     125    return false;
     126  }
     127  else
     128  {
     129    return json_decode($result, true);
     130  }
     131}
Note: See TracChangeset for help on using the changeset viewer.