Repository: privacyidea/privacyidea

Issue:
Mark privacyidea token in the qr code
We want to be able to distinguish privacyidea and non-privacyidea token in the app, so we are able to offer functionality based on that info. We need some kind of extra in the qr code for that.


Discussion:

Resolving patch:
diff --git a/privacyidea/lib/apps.py b/privacyidea/lib/apps.py
--- a/privacyidea/lib/apps.py
+++ b/privacyidea/lib/apps.py
@@ -98,7 +98,7 @@ def create_google_authenticator_url(key=None, user=None,
                                     serial="mylabel", tokenlabel="
",
                                     hash_algo="SHA1", digits="6",
                                     issuer="privacyIDEA", user_obj=None,
-                                    extra_data=None):
+                                    creator="privacyidea", extra_data=None):
     """
     This creates the google authenticator URL.
     This url may only be 119 characters long.
@@ -107,12 +107,12 @@ def create_google_authenticator_url(key=None, user=None,
     We expect the key to be hexlified!
     """
     extra_data = extra_data or {}
+    tokentype = tokentype.lower()
 
     # policy depends on some lib.util
 
     user_obj = user_obj or User()
-    if tokentype.lower() == "hotp":
-        tokentype = "hotp"
+    if tokentype == "hotp":
         counter = "counter=1&"
     else:
         counter = ""
@@ -152,9 +152,9 @@ def create_google_authenticator_url(key=None, user=None,
         # the QR code simpler
         hash_algo = ""
 
-    if tokentype.lower() == "totp":
+    if tokentype == "totp":
         period = "period={0!s}&".format(period)
-    elif tokentype.lower() == "daypassword":
+    elif tokentype == "daypassword":
         period = "period={0!s}&".format(parse_time_sec_int(period))
     else:
         period = ""
@@ -162,11 +162,12 @@ def create_google_authenticator_url(key=None, user=None,
     return ("otpauth://{tokentype!s}/{label!s}?secret={secret!s}&"
             "{counter!s}{hash!s}{period!s}"
             "digits={digits!s}&"
+            "creator={creator}&"
             "issuer={issuer!s}{extra}".format(tokentype=tokentype,
                                        label=url_label, secret=otpkey,
                                        hash=hash_algo, period=period,
                                        digits=digits, issuer=url_issuer,
-                                       counter=counter,
+                                       counter=counter, creator=creator,
                                        extra=_construct_extra_parameters(extra_data)))
 
 @log_with(log)


Test patch:
diff --git a/tests/test_lib_apps.py b/tests/test_lib_apps.py
--- a/tests/test_lib_apps.py
+++ b/tests/test_lib_apps.py
@@ -19,8 +19,8 @@ def test_01_apps_urls(self):
 
         r = create_google_authenticator_url(tokentype="TOTP", key="123456",
                                             period=60)
-        self.assertTrue("otpauth://TOTP/mylabel?secret=CI2FM&period"
-                        "=60&digits=6&issuer=privacyIDEA" in r, r)
+        self.assertTrue("otpauth://totp/mylabel?secret=CI2FM&period"
+                        "=60&digits=6&creator=privacyidea&issuer=privacyIDEA" in r, r)
 
         r = create_oathtoken_url("12345678")
         self.assertEqual(r, "oathtoken:///addToken?name=mylabel&"