[libgdata] Bug 644946 — Support two-factor authentication



commit 810d9d81676f8eb3462cce590e467bb55fead259
Author: Philip Withnall <philip tecnocode co uk>
Date:   Tue Mar 22 13:20:44 2011 +0000

    Bug 644946 â?? Support two-factor authentication
    
    Add support for notifying the user with a more specific error message if
    login failed due to them needing to enter an application-specific password.
    
    This adds the following new error code:
     â?¢ GDATA_AUTHENTICATION_ERROR_INVALID_SECOND_FACTOR
    
    Closes: bgo#644946

 gdata/gdata-service.c |   18 ++++++++++++++++++
 gdata/gdata-service.h |    4 +++-
 2 files changed, 21 insertions(+), 1 deletions(-)
---
diff --git a/gdata/gdata-service.c b/gdata/gdata-service.c
index 06ac033..35e112a 100644
--- a/gdata/gdata-service.c
+++ b/gdata/gdata-service.c
@@ -706,6 +706,24 @@ authenticate (GDataService *self, const gchar *username, const gchar *password,
 			goto protocol_error;
 		} else if (strncmp (error_start, "BadAuthentication", error_end - error_start) == 0) {
 			/* Looks like Error=BadAuthentication errors don't return a URI */
+			gchar *info_start, *info_end;
+
+			info_start = strstr (response_body, "Info=");
+			if (info_start != NULL) {
+				info_start += strlen ("Info=");
+				info_end = strstr (info_start, "\n");
+			}
+
+			/* If Info=InvalidSecondFactor, the user needs to generate an application-specific password and use that instead */
+			if (info_start != NULL && info_end != NULL && strncmp (info_start, "InvalidSecondFactor", info_end - info_start) == 0) {
+				g_set_error (error, GDATA_AUTHENTICATION_ERROR, GDATA_AUTHENTICATION_ERROR_INVALID_SECOND_FACTOR,
+				             /* Translators: the parameter is a URI for further information. */
+				             _("This account requires an application-specific password. (%s)"),
+				             "http://www.google.com/support/accounts/bin/static.py?page=guide.cs&guide=1056283&topic=1056286";);
+				goto login_error;
+			}
+
+			/* Fall back to a generic "bad authentication details" message */
 			g_set_error_literal (error, GDATA_AUTHENTICATION_ERROR, GDATA_AUTHENTICATION_ERROR_BAD_AUTHENTICATION,
 			                     _("Your username or password were incorrect."));
 			goto login_error;
diff --git a/gdata/gdata-service.h b/gdata/gdata-service.h
index 28d1e56..744d017 100644
--- a/gdata/gdata-service.h
+++ b/gdata/gdata-service.h
@@ -99,6 +99,7 @@ typedef enum {
  * @GDATA_AUTHENTICATION_ERROR_SERVICE_DISABLED: The user's access to the specified service has been disabled. (The user account may still be valid.)
  * @GDATA_AUTHENTICATION_ERROR_ACCOUNT_MIGRATED: The user's account login details have been migrated to a new system. (This is used for the transition
  * from the old YouTube login details to the new ones.)
+ * @GDATA_AUTHENTICATION_ERROR_INVALID_SECOND_FACTOR: The user's account requires an application-specific password to be used.
  *
  * Error codes for #GDataService authentication operations. See the
  * <ulink type="http" url="http://code.google.com/apis/accounts/docs/AuthForInstalledApps.html#Errors";>Google accounts documentation</ulink> for
@@ -112,7 +113,8 @@ typedef enum {
 	GDATA_AUTHENTICATION_ERROR_ACCOUNT_DELETED,
 	GDATA_AUTHENTICATION_ERROR_ACCOUNT_DISABLED,
 	GDATA_AUTHENTICATION_ERROR_SERVICE_DISABLED,
-	GDATA_AUTHENTICATION_ERROR_ACCOUNT_MIGRATED
+	GDATA_AUTHENTICATION_ERROR_ACCOUNT_MIGRATED,
+	GDATA_AUTHENTICATION_ERROR_INVALID_SECOND_FACTOR
 } GDataAuthenticationError;
 
 /**



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]