Revision: 1851
Author: olavmrk
Date: Wed Oct 14 00:44:24 2009
Log: SimpleSAML_Auth_Simple: Add getLoginURL().

This patch adds a function to retrieve a login URL that can be used
to log the user in with the authentication source.
http://code.google.com/p/simplesamlphp/source/detail?r=1851

Added:
  /trunk/modules/core/www/as_login.php
Modified:
  /trunk/lib/SimpleSAML/Auth/Simple.php

=======================================
--- /dev/null
+++ /trunk/modules/core/www/as_login.php        Wed Oct 14 00:44:24 2009
@@ -0,0 +1,23 @@
+<?php
+
+/**
+ * Endpoint for logging in with an authentication source.
+ *
+ * @package simpleSAMLphp
+ * @version $Id$
+ */
+
+if (!is_string($_REQUEST['ReturnTo'])) {
+       throw new SimpleSAML_Error_BadRequest('Missing ReturnTo parameter.');
+}
+
+if (!is_string($_REQUEST['AuthId'])) {
+       throw new SimpleSAML_Error_BadRequest('Missing AuthId parameter.');
+}
+
+$as = new SimpleSAML_Auth_Simple($_REQUEST['AuthId']);
+$as->requireAuth(array(
+       'url' => $_REQUEST['ReturnTo'],
+));
+
+SimpleSAML_Utilities::redirect($_REQUEST['ReturnTo']);
=======================================
--- /trunk/lib/SimpleSAML/Auth/Simple.php       Mon Oct  5 04:51:51 2009
+++ /trunk/lib/SimpleSAML/Auth/Simple.php       Wed Oct 14 00:44:24 2009
@@ -136,6 +136,31 @@
                $session = SimpleSAML_Session::getInstance();
                return $session->getAttributes();
        }
+
+
+       /**
+        * Retrieve an URL that can be used to log the user in.
+        *
+        * @param string|NULL $returnTo
+        *   The page the user should be returned to afterwards. If this 
parameter
+        *   is NULL, the user will be returned to the current page.
+        * @return string
+        *   An URL which is suitable for use in link-elements.
+        */
+       public function getLoginURL($returnTo = NULL) {
+
+               if ($returnTo === NULL) {
+                       $returnTo = SimpleSAML_Utilities::selfURL();
+               }
+
+               $login = SimpleSAML_Module::getModuleURL('core/as_login.php');
+               $login = SimpleSAML_Utilities::addURLparameter($login, array(
+                       'AuthId' => $this->authSource,
+                       'ReturnTo' => $returnTo,
+               ));
+
+               return $login;
+       }

  }


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"simpleSAMLphp commits" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/simplesamlphp-commits?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to