prompt: We are currently solving the following issue within our repository. Here is the issue text:
  --- BEGIN ISSUE ---
  Fix typo in registration token
  The example of the registration token contains a typo.
  The toketype of course is a "registration" token, not a "register".
  
  --- END ISSUE ---
  
  Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
  --- BEGIN FILES ---
  Path: `privacyidea/lib/tokens/registrationtoken.py`
  Content:
  ```
  1 # -*- coding: utf-8 -*-
  2 #
  3 #  privacyIDEA
  4 #  Aug 12, 2014 Cornelius Kölbel
  5 #  License:  AGPLv3
  6 #  contact:  http://www.privacyidea.org
  7 #
  8 #  2015-01-29 Adapt during migration to flask
  9 #             Cornelius Kölbel <cornelius@privacyidea.org>
  10 #
  11 # This code is free software; you can redistribute it and/or
  12 # modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE
  13 # License as published by the Free Software Foundation; either
  14 # version 3 of the License, or any later version.
  15 #
  16 # This code is distributed in the hope that it will be useful,
  17 # but WITHOUT ANY WARRANTY; without even the implied warranty of
  18 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  19 # GNU AFFERO GENERAL PUBLIC LICENSE for more details.
  20 #
  21 # You should have received a copy of the GNU Affero General Public
  22 # License along with this program.  If not, see <http://www.gnu.org/licenses/>.
  23 #
  24 """
  25 This file contains the definition of the RegisterToken class.
  26 
  27 The code is tested in test_lib_tokens_registration.py.
  28 """
  29 
  30 import logging
  31 
  32 from privacyidea.lib.utils import to_unicode
  33 from privacyidea.lib.tokens.passwordtoken import PasswordTokenClass
  34 from privacyidea.lib.log import log_with
  35 from privacyidea.lib.crypto import generate_password
  36 from privacyidea.lib.decorators import check_token_locked
  37 from privacyidea.lib import _
  38 
  39 optional = True
  40 required = False
  41 
  42 log = logging.getLogger(__name__)
  43 
  44 
  45 class RegistrationTokenClass(PasswordTokenClass):
  46     """
  47     Token to implement a registration code.
  48     It can be used to create a registration code or a "TAN" which can be used
  49     once by a user to authenticate somewhere. After this registration code is
  50     used, the token is automatically deleted.
  51 
  52     The idea is to provide a workflow, where the user can get a registration code
  53     by e.g. postal mail and then use this code as the initial first factor to
  54     authenticate to the UI to enroll real tokens.
  55 
  56     A registration code can be created by an administrative task with the
  57     token/init api like this:
  58 
  59       **Example Authentication Request**:
  60 
  61         .. sourcecode:: http
  62 
  63            POST /token/init HTTP/1.1
  64            Host: example.com
  65            Accept: application/json
  66 
  67            type=register
  68            user=cornelius
  69            realm=realm1
  70 
  71       **Example response**:
  72 
  73            .. sourcecode:: http
  74 
  75                HTTP/1.1 200 OK
  76                Content-Type: application/json
  77 
  78                {
  79                   "detail": {
  80                     "registrationcode": "12345808124095097608"
  81                   },
  82                   "id": 1,
  83                   "jsonrpc": "2.0",
  84                   "result": {
  85                     "status": true,
  86                     "value": true
  87                   },
  88                   "version": "privacyIDEA unknown"
  89                 }
  90 
  91     """
  92 
  93     def __init__(self, aToken):
  94         PasswordTokenClass.__init__(self, aToken)
  95         self.hKeyRequired = False
  96         self.set_type(u"registration")
  97         self.otp_len = 24
  98 
  99     @staticmethod
  100     def get_class_type():
  101         return "registration"
  102 
  103     @staticmethod
  104     def get_class_prefix():
  105         return "REG"
  106 
  107     @staticmethod
  108     @log_with(log)
  109     def get_class_info(key=None, ret='all'):
  110         """
  111         returns a subtree of the token definition
  112 
  113         :param key: subsection identifier
  114         :type key: string
  115         :param ret: default return value, if nothing is found
  116         :type ret: user defined
  117         :return: subsection if key exists or user defined
  118         :rtype: dict or scalar
  119         """
  120         res = {'type': 'registration',
  121                'title': 'Registration Code Token',
  122                'description': _('Registration: A token that creates a '
  123                                 'registration code that '
  124                                 'can be used as a second factor once.'),
  125                'init': {},
  126                'config': {},
  127                'user':  [],
  128                # This tokentype is enrollable in the UI for...
  129                'ui_enroll': ["admin"],
  130                'policy': {},
  131                }
  132 
  133         if key:
  134             ret = res.get(key)
  135         else:
  136             if ret == 'all':
  137                 ret = res
  138         return ret
  139 
  140     def update(self, param):
  141         """
  142         This method is called during the initialization process.
  143         :param param: parameters from the token init
  144         :type param: dict
  145         :return: None
  146         """
  147         if "genkey" in param:
  148             # We do not need the genkey! We generate anyway.
  149             # Otherwise genkey and otpkey will raise an exception in
  150             # PasswordTokenClass
  151             del param["genkey"]
  152         param["otpkey"] = generate_password(size=self.otp_len)
  153         PasswordTokenClass.update(self, param)
  154 
  155     @log_with(log, log_entry=False)
  156     @check_token_locked
  157     def inc_count_auth_success(self):
  158         """
  159         Increase the counter, that counts successful authentications
  160         In case of successful authentication the token does needs to be deleted.
  161         """
  162         self.delete_token()
  163         return 1
  164 
  165     @log_with(log)
  166     def get_init_detail(self, params=None, user=None):
  167         """
  168         At the end of the initialization we return the registration code.
  169         """
  170         response_detail = PasswordTokenClass.get_init_detail(self, params, user)
  171         params = params or {}
  172         secretHOtp = self.token.get_otpkey()
  173         registrationcode = secretHOtp.getKey()
  174         response_detail["registrationcode"] = to_unicode(registrationcode)
  175         return response_detail
  176
  ```
  --- END FILES ---
  
  Please first localize the bug based on the issue statement, and then generate a patch according to the `git diff` format fenced by three backticks.
  
  Here is an example:
  
  ```diff
  diff --git a/examples/server_async.py b/examples/server_async.py
  --- a/examples/server_async.py
  +++ b/examples/server_async.py
  @@ -313,4 +313,4 @@
   
   
   if __name__ == "__main__":
  -    asyncio.run(run_async_server("."), debug=True)
  +    asyncio.run(run_async_server(), debug=True)
  diff --git a/examples/server_sync.py b/examples/server_sync.py
  --- a/examples/server_sync.py
  +++ b/examples/server_sync.py
  @@ -313,5 +313,5 @@
   
   
   if __name__ == "__main__":
  -    server = run_sync_server(".")
  +    server = run_sync_server()
       server.shutdown()
  
  ```
  
golden_diff: diff --git a/privacyidea/lib/tokens/registrationtoken.py b/privacyidea/lib/tokens/registrationtoken.py
  --- a/privacyidea/lib/tokens/registrationtoken.py
  +++ b/privacyidea/lib/tokens/registrationtoken.py
  @@ -64,7 +64,7 @@
              Host: example.com
              Accept: application/json
   
  -           type=register
  +           type=registration
              user=cornelius
              realm=realm1
  
verification_info: {"golden_diff": "diff --git a/privacyidea/lib/tokens/registrationtoken.py b/privacyidea/lib/tokens/registrationtoken.py\n--- a/privacyidea/lib/tokens/registrationtoken.py\n+++ b/privacyidea/lib/tokens/registrationtoken.py\n@@ -64,7 +64,7 @@\n            Host: example.com\n            Accept: application/json\n \n-           type=register\n+           type=registration\n            user=cornelius\n            realm=realm1\n", "issue": "Fix typo in registration token\nThe example of the registration token contains a typo.\r\nThe toketype of course is a \"registration\" token, not a \"register\".\n", "before_files": [{"content": "# -*- coding: utf-8 -*-\n#\n#  privacyIDEA\n#  Aug 12, 2014 Cornelius K\u00f6lbel\n#  License:  AGPLv3\n#  contact:  http://www.privacyidea.org\n#\n#  2015-01-29 Adapt during migration to flask\n#             Cornelius K\u00f6lbel <cornelius@privacyidea.org>\n#\n# This code is free software; you can redistribute it and/or\n# modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE\n# License as published by the Free Software Foundation; either\n# version 3 of the License, or any later version.\n#\n# This code is distributed in the hope that it will be useful,\n# but WITHOUT ANY WARRANTY; without even the implied warranty of\n# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n# GNU AFFERO GENERAL PUBLIC LICENSE for more details.\n#\n# You should have received a copy of the GNU Affero General Public\n# License along with this program.  If not, see <http://www.gnu.org/licenses/>.\n#\n\"\"\"\nThis file contains the definition of the RegisterToken class.\n\nThe code is tested in test_lib_tokens_registration.py.\n\"\"\"\n\nimport logging\n\nfrom privacyidea.lib.utils import to_unicode\nfrom privacyidea.lib.tokens.passwordtoken import PasswordTokenClass\nfrom privacyidea.lib.log import log_with\nfrom privacyidea.lib.crypto import generate_password\nfrom privacyidea.lib.decorators import check_token_locked\nfrom privacyidea.lib import _\n\noptional = True\nrequired = False\n\nlog = logging.getLogger(__name__)\n\n\nclass RegistrationTokenClass(PasswordTokenClass):\n    \"\"\"\n    Token to implement a registration code.\n    It can be used to create a registration code or a \"TAN\" which can be used\n    once by a user to authenticate somewhere. After this registration code is\n    used, the token is automatically deleted.\n\n    The idea is to provide a workflow, where the user can get a registration code\n    by e.g. postal mail and then use this code as the initial first factor to\n    authenticate to the UI to enroll real tokens.\n\n    A registration code can be created by an administrative task with the\n    token/init api like this:\n\n      **Example Authentication Request**:\n\n        .. sourcecode:: http\n\n           POST /token/init HTTP/1.1\n           Host: example.com\n           Accept: application/json\n\n           type=register\n           user=cornelius\n           realm=realm1\n\n      **Example response**:\n\n           .. sourcecode:: http\n\n               HTTP/1.1 200 OK\n               Content-Type: application/json\n\n               {\n                  \"detail\": {\n                    \"registrationcode\": \"12345808124095097608\"\n                  },\n                  \"id\": 1,\n                  \"jsonrpc\": \"2.0\",\n                  \"result\": {\n                    \"status\": true,\n                    \"value\": true\n                  },\n                  \"version\": \"privacyIDEA unknown\"\n                }\n\n    \"\"\"\n\n    def __init__(self, aToken):\n        PasswordTokenClass.__init__(self, aToken)\n        self.hKeyRequired = False\n        self.set_type(u\"registration\")\n        self.otp_len = 24\n\n    @staticmethod\n    def get_class_type():\n        return \"registration\"\n\n    @staticmethod\n    def get_class_prefix():\n        return \"REG\"\n\n    @staticmethod\n    @log_with(log)\n    def get_class_info(key=None, ret='all'):\n        \"\"\"\n        returns a subtree of the token definition\n\n        :param key: subsection identifier\n        :type key: string\n        :param ret: default return value, if nothing is found\n        :type ret: user defined\n        :return: subsection if key exists or user defined\n        :rtype: dict or scalar\n        \"\"\"\n        res = {'type': 'registration',\n               'title': 'Registration Code Token',\n               'description': _('Registration: A token that creates a '\n                                'registration code that '\n                                'can be used as a second factor once.'),\n               'init': {},\n               'config': {},\n               'user':  [],\n               # This tokentype is enrollable in the UI for...\n               'ui_enroll': [\"admin\"],\n               'policy': {},\n               }\n\n        if key:\n            ret = res.get(key)\n        else:\n            if ret == 'all':\n                ret = res\n        return ret\n\n    def update(self, param):\n        \"\"\"\n        This method is called during the initialization process.\n        :param param: parameters from the token init\n        :type param: dict\n        :return: None\n        \"\"\"\n        if \"genkey\" in param:\n            # We do not need the genkey! We generate anyway.\n            # Otherwise genkey and otpkey will raise an exception in\n            # PasswordTokenClass\n            del param[\"genkey\"]\n        param[\"otpkey\"] = generate_password(size=self.otp_len)\n        PasswordTokenClass.update(self, param)\n\n    @log_with(log, log_entry=False)\n    @check_token_locked\n    def inc_count_auth_success(self):\n        \"\"\"\n        Increase the counter, that counts successful authentications\n        In case of successful authentication the token does needs to be deleted.\n        \"\"\"\n        self.delete_token()\n        return 1\n\n    @log_with(log)\n    def get_init_detail(self, params=None, user=None):\n        \"\"\"\n        At the end of the initialization we return the registration code.\n        \"\"\"\n        response_detail = PasswordTokenClass.get_init_detail(self, params, user)\n        params = params or {}\n        secretHOtp = self.token.get_otpkey()\n        registrationcode = secretHOtp.getKey()\n        response_detail[\"registrationcode\"] = to_unicode(registrationcode)\n        return response_detail\n", "path": "privacyidea/lib/tokens/registrationtoken.py"}], "after_files": [{"content": "# -*- coding: utf-8 -*-\n#\n#  privacyIDEA\n#  Aug 12, 2014 Cornelius K\u00f6lbel\n#  License:  AGPLv3\n#  contact:  http://www.privacyidea.org\n#\n#  2015-01-29 Adapt during migration to flask\n#             Cornelius K\u00f6lbel <cornelius@privacyidea.org>\n#\n# This code is free software; you can redistribute it and/or\n# modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE\n# License as published by the Free Software Foundation; either\n# version 3 of the License, or any later version.\n#\n# This code is distributed in the hope that it will be useful,\n# but WITHOUT ANY WARRANTY; without even the implied warranty of\n# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n# GNU AFFERO GENERAL PUBLIC LICENSE for more details.\n#\n# You should have received a copy of the GNU Affero General Public\n# License along with this program.  If not, see <http://www.gnu.org/licenses/>.\n#\n\"\"\"\nThis file contains the definition of the RegisterToken class.\n\nThe code is tested in test_lib_tokens_registration.py.\n\"\"\"\n\nimport logging\n\nfrom privacyidea.lib.utils import to_unicode\nfrom privacyidea.lib.tokens.passwordtoken import PasswordTokenClass\nfrom privacyidea.lib.log import log_with\nfrom privacyidea.lib.crypto import generate_password\nfrom privacyidea.lib.decorators import check_token_locked\nfrom privacyidea.lib import _\n\noptional = True\nrequired = False\n\nlog = logging.getLogger(__name__)\n\n\nclass RegistrationTokenClass(PasswordTokenClass):\n    \"\"\"\n    Token to implement a registration code.\n    It can be used to create a registration code or a \"TAN\" which can be used\n    once by a user to authenticate somewhere. After this registration code is\n    used, the token is automatically deleted.\n\n    The idea is to provide a workflow, where the user can get a registration code\n    by e.g. postal mail and then use this code as the initial first factor to\n    authenticate to the UI to enroll real tokens.\n\n    A registration code can be created by an administrative task with the\n    token/init api like this:\n\n      **Example Authentication Request**:\n\n        .. sourcecode:: http\n\n           POST /token/init HTTP/1.1\n           Host: example.com\n           Accept: application/json\n\n           type=registration\n           user=cornelius\n           realm=realm1\n\n      **Example response**:\n\n           .. sourcecode:: http\n\n               HTTP/1.1 200 OK\n               Content-Type: application/json\n\n               {\n                  \"detail\": {\n                    \"registrationcode\": \"12345808124095097608\"\n                  },\n                  \"id\": 1,\n                  \"jsonrpc\": \"2.0\",\n                  \"result\": {\n                    \"status\": true,\n                    \"value\": true\n                  },\n                  \"version\": \"privacyIDEA unknown\"\n                }\n\n    \"\"\"\n\n    def __init__(self, aToken):\n        PasswordTokenClass.__init__(self, aToken)\n        self.hKeyRequired = False\n        self.set_type(u\"registration\")\n        self.otp_len = 24\n\n    @staticmethod\n    def get_class_type():\n        return \"registration\"\n\n    @staticmethod\n    def get_class_prefix():\n        return \"REG\"\n\n    @staticmethod\n    @log_with(log)\n    def get_class_info(key=None, ret='all'):\n        \"\"\"\n        returns a subtree of the token definition\n\n        :param key: subsection identifier\n        :type key: string\n        :param ret: default return value, if nothing is found\n        :type ret: user defined\n        :return: subsection if key exists or user defined\n        :rtype: dict or scalar\n        \"\"\"\n        res = {'type': 'registration',\n               'title': 'Registration Code Token',\n               'description': _('Registration: A token that creates a '\n                                'registration code that '\n                                'can be used as a second factor once.'),\n               'init': {},\n               'config': {},\n               'user':  [],\n               # This tokentype is enrollable in the UI for...\n               'ui_enroll': [\"admin\"],\n               'policy': {},\n               }\n\n        if key:\n            ret = res.get(key)\n        else:\n            if ret == 'all':\n                ret = res\n        return ret\n\n    def update(self, param):\n        \"\"\"\n        This method is called during the initialization process.\n        :param param: parameters from the token init\n        :type param: dict\n        :return: None\n        \"\"\"\n        if \"genkey\" in param:\n            # We do not need the genkey! We generate anyway.\n            # Otherwise genkey and otpkey will raise an exception in\n            # PasswordTokenClass\n            del param[\"genkey\"]\n        param[\"otpkey\"] = generate_password(size=self.otp_len)\n        PasswordTokenClass.update(self, param)\n\n    @log_with(log, log_entry=False)\n    @check_token_locked\n    def inc_count_auth_success(self):\n        \"\"\"\n        Increase the counter, that counts successful authentications\n        In case of successful authentication the token does needs to be deleted.\n        \"\"\"\n        self.delete_token()\n        return 1\n\n    @log_with(log)\n    def get_init_detail(self, params=None, user=None):\n        \"\"\"\n        At the end of the initialization we return the registration code.\n        \"\"\"\n        response_detail = PasswordTokenClass.get_init_detail(self, params, user)\n        params = params or {}\n        secretHOtp = self.token.get_otpkey()\n        registrationcode = secretHOtp.getKey()\n        response_detail[\"registrationcode\"] = to_unicode(registrationcode)\n        return response_detail\n", "path": "privacyidea/lib/tokens/registrationtoken.py"}]}