Enginio REST API User Creation?



  • Hi everyone,

    This is my first post, so please be kind. :)

    The QML documentation makes creating users easy, and I assume the QT classes are similar, but I don't see an obvious way to create new user accounts programmatically with Node.js, HTML5 or REST. Can someone point me to the best way to create new Enginio users with the REST API? I'm probably missing something obvious, but I've combed through the documentation and not seen an obvious example.

    Thanks,

    MoreCowbell



  • I'll partially answer my own question. I see there is a POST create user in the REST API. When I looked at the reference page last, the link was broken for whatever reason; maybe a bad browser cache, or similar.

    The user creation looks straight forward, although I haven't tried it yet. I also see the oauth2 token creation request.

    So .. I know that I must submit an auth token with my user creation request. I assume that it can be the token generated by any user with "Create" access to the Users collection? Anyway, I'll give it a try and we'll see what we see.



  • Well, I'm getting a response of:
    {
    "error":"unsupported_grant_type",
    "error_description":"supported types: password, refresh_token"
    }

    when I'm passing in a grant_type of "password" which is puzzling ...



  • Hello, there is an example but in C++ not QML. It works for me.

    creating_user_enginio.pro
    @
    #-------------------------------------------------

    Project created by QtCreator 2014-10-21T09:12:33

    #-------------------------------------------------

    QT += network gui widgets enginio

    greaterThan(QT_MAJOR_VERSION, 4): QT += widgets

    TARGET = creating_user_enginio
    TEMPLATE = app

    SOURCES += main.cpp
    Widget.cpp

    HEADERS += Widget.h

    FORMS += Widget.ui
    @

    Widget.h
    @
    #ifndef WIDGET_H
    #define WIDGET_H

    #include <QDebug>
    #include <QWidget>
    #include <Enginio>

    namespace Ui {
    class Widget;
    }

    class Widget : public QWidget
    {
    Q_OBJECT

    public:
    explicit Widget(QWidget *parent = 0);
    ~Widget();

    protected slots:
    void createUserButtonClicked();
    void replyFinished(EnginioReply *reply);

    private:
    Ui::Widget *ui;
    EnginioClient *m_client;
    };

    #endif // WIDGET_H
    @

    Widget.cpp
    @
    #include "Widget.h"
    #include "ui_Widget.h"

    Widget::Widget(QWidget *parent) :
    QWidget(parent),
    ui(new Ui::Widget)
    {
    ui->setupUi(this);
    connect(ui->pushButton, SIGNAL(clicked()), this, SLOT(createUserButtonClicked()));
    //
    QByteArray backendId("YOUR_EDS_INSTANCE_ID"); // copy/paste your EDS instance backend id here
    m_client = new EnginioClient;
    m_client->setBackendId(backendId);
    }

    Widget::~Widget()
    {
    delete ui;
    }

    void Widget::createUserButtonClicked()
    {
    if(!ui->username->text().isEmpty()){
    if(!ui->password->text().isEmpty() && !ui->confirmPassword->text().isEmpty()) {
    if (!ui->password->text().compare(ui->confirmPassword->text())) {
    qDebug() << "password confirmation ok";
    QJsonObject object;
    object["objectType"] = QString::fromUtf8("users");
    object["username"] = ui->username->text();
    object["password"] = ui->password->text();
    EnginioReply reply = m_client->create(object);
    connect(reply, SIGNAL(finished(EnginioReply
    )), this, SLOT(replyFinished(EnginioReply*)));
    } else {
    qDebug() << "password confirmation failed";
    }
    } else {
    qDebug() << "please fill password and/or confirm password fields.";
    }
    } else {
    qDebug() << "please fill username field";
    }
    }

    void Widget::replyFinished(EnginioReply *reply)
    {
    if (reply->isError()) {
    qDebug() << "Ooops! Something went wrong!" << reply->data();
    }
    else {
    qDebug() << "The object was created" << reply->data();
    }
    reply->deleteLater();
    }
    @

    Widget.ui
    @
    <?xml version="1.0" encoding="UTF-8"?>
    <ui version="4.0">
    <class>Widget</class>
    <widget class="QWidget" name="Widget">
    <property name="geometry">
    <rect>
    <x>0</x>
    <y>0</y>
    <width>429</width>
    <height>135</height>
    </rect>
    </property>
    <property name="windowTitle">
    <string>Widget</string>
    </property>
    <layout class="QVBoxLayout" name="verticalLayout">
    <item>
    <layout class="QFormLayout" name="formLayout">
    <item row="0" column="0">
    <widget class="QLabel" name="label">
    <property name="text">
    <string>User</string>
    </property>
    </widget>
    </item>
    <item row="0" column="1">
    <widget class="QLineEdit" name="username"/>
    </item>
    <item row="1" column="0">
    <widget class="QLabel" name="label_2">
    <property name="text">
    <string>Password</string>
    </property>
    </widget>
    </item>
    <item row="1" column="1">
    <widget class="QLineEdit" name="password">
    <property name="echoMode">
    <enum>QLineEdit::Password</enum>
    </property>
    </widget>
    </item>
    <item row="2" column="0">
    <widget class="QLabel" name="label_3">
    <property name="text">
    <string>Confirm Password</string>
    </property>
    </widget>
    </item>
    <item row="2" column="1">
    <widget class="QLineEdit" name="confirmPassword">
    <property name="echoMode">
    <enum>QLineEdit::Password</enum>
    </property>
    </widget>
    </item>
    </layout>
    </item>
    <item>
    <widget class="QPushButton" name="pushButton">
    <property name="text">
    <string>PushButton</string>
    </property>
    </widget>
    </item>
    </layout>
    </widget>
    <layoutdefault spacing="6" margin="11"/>
    <resources/>
    <connections/>
    </ui>
    @


  • cid:52:privileges:purge

    Rest api doc for creating a new user is here : https://developer.qtcloudservices.com/eds/rest/v1/post_users



  • To clarify: my last post was the response to a /v1/auth/oauth2/token request so that I can perform my user creation request as an authenticated user.

    I'm posting to:
    POST /v1/auth/oauth2/token HTTP/1.1
    My message is:
    {"username":"spam","password":"spam", "grant_type":"password"}
    (the escaped colons are to make the string display on this forum; they are not in the message)
    And my content-type is application-json.

    The key point is "grant_type":"password" and the response of unsupported_grant_type with the error description of supported types [ password, refresh_token ]

    There seems to be a small missing piece that's breaking the response.

    Any ideas? I've done a full dump of both the post and the response and there's nothing obviously wrong.



  • With this code I can authenticate user on EDS service.
    Maybe it will help you.

    Widget.h
    @
    #ifndef WIDGET_H
    #define WIDGET_H

    #include <Enginio>
    #include <QDebug>
    #include <QWidget>

    namespace Ui {
    class Widget;
    }

    class Widget : public QWidget
    {
    Q_OBJECT

    public:
    explicit Widget(QWidget *parent = 0);
    ~Widget();

    protected slots:
    void loginButtonClicked();
    void authenticateStateChanged(Enginio::AuthenticationState state);

    private:
    Ui::Widget *ui;
    EnginioClient *m_client;
    EnginioOAuth2Authentication *m_identity;
    };

    #endif // WIDGET_H
    @

    Widget.cpp

    @
    #include "Widget.h"
    #include "ui_Widget.h"

    Widget::Widget(QWidget *parent) :
    QWidget(parent),
    ui(new Ui::Widget)
    {
    ui->setupUi(this);
    m_client = new EnginioClient;
    QByteArray backendId("YOUR_EDS_INSTANCE"); // copy/paste your EDS instance backend id here
    m_identity = new EnginioOAuth2Authentication;
    m_client->setBackendId(backendId);
    connect(ui->pushButton, SIGNAL(clicked()),
    this, SLOT(loginButtonClicked()));
    connect(m_client, SIGNAL(authenticationStateChanged(Enginio::AuthenticationState)),
    this, SLOT(authenticateStateChanged(Enginio::AuthenticationState)));
    }

    Widget::~Widget()
    {
    delete ui;
    }

    void Widget::loginButtonClicked()
    {
    m_identity->setUser(ui->username->text());
    m_identity->setPassword(ui->password->text());
    m_client->setIdentity(m_identity);
    }

    void Widget::authenticateStateChanged(Enginio::AuthenticationState state)
    {
    switch (state) {
    case Enginio::NotAuthenticated:
    qDebug() << "NotAuthenticated";
    break;
    case Enginio::Authenticating:
    qDebug() << "Authenticating";
    break;
    case Enginio::Authenticated:
    qDebug() << "Authenticated";
    break;
    case Enginio::AuthenticationFailure:
    qDebug() << "AuthenticationFailure";
    break;
    }
    qDebug() << state;
    }
    @

    Widget.ui

    @
    <?xml version="1.0" encoding="UTF-8"?>
    <ui version="4.0">
    <class>Widget</class>
    <widget class="QWidget" name="Widget">
    <property name="geometry">
    <rect>
    <x>0</x>
    <y>0</y>
    <width>383</width>
    <height>101</height>
    </rect>
    </property>
    <property name="windowTitle">
    <string>Widget</string>
    </property>
    <layout class="QVBoxLayout" name="verticalLayout">
    <item>
    <layout class="QFormLayout" name="formLayout">
    <item row="0" column="0">
    <widget class="QLabel" name="label">
    <property name="text">
    <string>Username</string>
    </property>
    </widget>
    </item>
    <item row="0" column="1">
    <widget class="QLineEdit" name="username"/>
    </item>
    <item row="1" column="0">
    <widget class="QLabel" name="label_2">
    <property name="text">
    <string>Password</string>
    </property>
    </widget>
    </item>
    <item row="1" column="1">
    <widget class="QLineEdit" name="password">
    <property name="echoMode">
    <enum>QLineEdit::Password</enum>
    </property>
    </widget>
    </item>
    </layout>
    </item>
    <item>
    <widget class="QPushButton" name="pushButton">
    <property name="text">
    <string>Login</string>
    </property>
    </widget>
    </item>
    </layout>
    </widget>
    <layoutdefault spacing="6" margin="11"/>
    <resources/>
    <connections/>
    </ui>
    @



  • I really appreciate the effort Daniel, but the EnginioClient object, in both C++ and via QML appears to work correctly without problems. It's the REST API that's giving me trouble. If I had shell access on the machine from which I'm trying to execute Enginio commands, I'd have just used EnginioClient via Qt/C++.



  • What are you using? curl ? python script ?

    Best Regards



  • Hi Daniel,

    Yes, the simplest way to exercise the interface appeared to be with Curl. After that works, I'll do the same thing with an Ajax call, and probably PHP.

    Thanks


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.