Create a personal access token.

        A token that is bound to a specific user and which doesn't expire, i.e.
        similar to the concept of an API key.

        :param name: Client name.
        :param user_id: User ID.
        :param scopes: The list of permitted scopes. (Default: ``None``)
        :param is_internal: If ``True`` it's a internal access token.
             (Default: ``False``)
        :returns: A new access token.

def create_personal(cls, name, user_id, scopes=None, is_internal=False):
        """Create a personal access token.

        A token that is bound to a specific user and which doesn't expire, i.e.
        similar to the concept of an API key.

        :param name: Client name.
        :param user_id: User ID.
        :param scopes: The list of permitted scopes. (Default: ``None``)
        :param is_internal: If ``True`` it's a internal access token.
             (Default: ``False``)
        :returns: A new access token.
        """
        with db.session.begin_nested():
            scopes = " ".join(scopes) if scopes else ""

            c = Client(
                name=name,
                user_id=user_id,
                is_internal=True,
                is_confidential=False,
                _default_scopes=scopes
            )
            c.gen_salt()

            t = Token(
                client_id=c.client_id,
                user_id=user_id,
                access_token=gen_salt(
                    current_app.config.get(
                        'OAUTH2SERVER_TOKEN_PERSONAL_SALT_LEN')
                ),
                expires=None,
                _scopes=scopes,
                is_personal=True,
                is_internal=is_internal,
            )

            db.session.add(c)
            db.session.add(t)

        return t