diff --git a/docs/simplesamlphp-sp-api.txt b/docs/simplesamlphp-sp-api.txt
index 90969e1a951c23c69a2335f5a5af371330ab2612..54cd65a895db1c8bdf7af068e8a88b5c494c4524 100644
--- a/docs/simplesamlphp-sp-api.txt
+++ b/docs/simplesamlphp-sp-api.txt
@@ -98,6 +98,10 @@ The following global parameters are supported:
 :   The URL the user should be returned to after authentication.
     The default is to return the user to the current page.
 
+`ReturnCallback` (`array`)
+
+:   The function we should call when the user finishes authentication.
+
 The [`saml:SP`](./saml:sp) authentication source also defines some parameters.
 
 
diff --git a/lib/SimpleSAML/Auth/Simple.php b/lib/SimpleSAML/Auth/Simple.php
index b45d07bede101295f9ada9c775edc4538934f42b..d036a1aa4558f95d43b5124aa283810a29983ba1 100644
--- a/lib/SimpleSAML/Auth/Simple.php
+++ b/lib/SimpleSAML/Auth/Simple.php
@@ -83,6 +83,8 @@ class SimpleSAML_Auth_Simple {
 	 *  - 'KeepPost': If the current request is a POST request, keep the POST
 	 *    data until after the authentication.
 	 *  - 'ReturnTo': The URL the user should be returned to after authentication.
+	 *  - 'ReturnCallback': The function we should call after the user has
+	 *    finished authentication.
 	 *
 	 * @param array $params  Various options to the authentication request.
 	 */
@@ -96,6 +98,8 @@ class SimpleSAML_Auth_Simple {
 
 		if (array_key_exists('ReturnTo', $params)) {
 			$returnTo = (string)$params['ReturnTo'];
+		} else if (array_key_exists('ReturnCallback', $params)) {
+			$returnTo = (array)$params['ReturnCallback'];
 		} else {
 			$returnTo = SimpleSAML_Utilities::selfURL();
 		}
@@ -111,7 +115,7 @@ class SimpleSAML_Auth_Simple {
 		}
 
 
-		if (!isset($params[SimpleSAML_Auth_State::RESTART])) {
+		if (!isset($params[SimpleSAML_Auth_State::RESTART]) && is_string($returnTo)) {
 			/*
 			 * An URL to restart the authentication, in case the user bookmarks
 			 * something, e.g. the discovery service page.