From 0388d164efd15cf252c93b1d0e3ca46b5f9d82bf Mon Sep 17 00:00:00 2001
From: Olav Morken <olav.morken@uninett.no>
Date: Tue, 9 Nov 2010 10:07:05 +0000
Subject: [PATCH] openid: Add target parameter + google example.

git-svn-id: https://simplesamlphp.googlecode.com/svn/trunk@2626 44740490-163a-0410-bde0-09ae8108e29a
---
 config-templates/authsources.php               | 18 ++++++++++++++++++
 .../openid/lib/Auth/Source/OpenIDConsumer.php  | 15 +++++++++++++++
 2 files changed, 33 insertions(+)

diff --git a/config-templates/authsources.php b/config-templates/authsources.php
index 9efcc665a..a1ffb94c2 100644
--- a/config-templates/authsources.php
+++ b/config-templates/authsources.php
@@ -92,6 +92,24 @@ $config = array(
 	),
 	*/
 
+	/*
+	// Example of an authsource that authenticates against Google.
+	// See: http://code.google.com/apis/accounts/docs/OpenID.html
+	'google' => array(
+		'openid:OpenIDConsumer',
+		// Googles OpenID endpoint.
+		'target' => 'https://www.google.com/accounts/o8/id',
+		// Attributes that google can supply.
+		'attributes.ax_required' => array(
+			//'http://axschema.org/namePerson/first',
+			//'http://axschema.org/namePerson/last',
+			//'http://axschema.org/contact/email',
+			//'http://axschema.org/contact/country/home',
+			//'http://axschema.org/pref/language',
+		),
+	),
+	*/
+
 	/*
 	'papi' => array(
 		'authpapi:PAPI',
diff --git a/modules/openid/lib/Auth/Source/OpenIDConsumer.php b/modules/openid/lib/Auth/Source/OpenIDConsumer.php
index da8fd184c..a28fddd86 100644
--- a/modules/openid/lib/Auth/Source/OpenIDConsumer.php
+++ b/modules/openid/lib/Auth/Source/OpenIDConsumer.php
@@ -24,6 +24,14 @@ require_once('Auth/OpenID/ServerRequest.php');
  */
 class sspmod_openid_Auth_Source_OpenIDConsumer extends SimpleSAML_Auth_Source {
 
+	/**
+	 * Static openid target to use.
+	 *
+	 * @var string|NULL
+	 */
+	private $target;
+
+
 	/**
 	 * List of optional attributes.
 	 */
@@ -56,6 +64,8 @@ class sspmod_openid_Auth_Source_OpenIDConsumer extends SimpleSAML_Auth_Source {
 		$cfgParse = SimpleSAML_Configuration::loadFromArray($config,
 			'Authentication source ' . var_export($this->authId, TRUE));
 
+		$this->target = $cfgParse->getString('target', NULL);
+
 		$this->optionalAttributes = $cfgParse->getArray('attributes.optional', array());
 		$this->requiredAttributes = $cfgParse->getArray('attributes.required', array());
 
@@ -76,6 +86,11 @@ class sspmod_openid_Auth_Source_OpenIDConsumer extends SimpleSAML_Auth_Source {
 		assert('is_array($state)');
 
 		$state['openid:AuthId'] = $this->authId;
+
+		if ($this->target !== NULL) {
+			$this->doAuth($state, $this->target);
+		}
+
 		$id = SimpleSAML_Auth_State::saveState($state, 'openid:state');
 
 		$url = SimpleSAML_Module::getModuleURL('openid/consumer.php');
-- 
GitLab