Rename payload->nonce in new passport scopes.

This commit is contained in:
John Preston 2018-08-17 14:01:23 +03:00
parent fddc3d6ad9
commit 6bf3006eb9
3 changed files with 20 additions and 9 deletions

View File

@ -862,7 +862,9 @@ bool Messenger::openLocalUrl(const QString &url, QVariant context) {
const auto scope = params.value("scope", QString()); const auto scope = params.value("scope", QString());
const auto callback = params.value("callback_url", QString()); const auto callback = params.value("callback_url", QString());
const auto publicKey = params.value("public_key", QString()); const auto publicKey = params.value("public_key", QString());
const auto payload = params.value("payload", QString()); const auto nonce = params.value(
Passport::NonceNameByScope(scope),
QString());
const auto errors = params.value("errors", QString()); const auto errors = params.value("errors", QString());
if (const auto window = App::wnd()) { if (const auto window = App::wnd()) {
if (const auto controller = window->controller()) { if (const auto controller = window->controller()) {
@ -871,7 +873,7 @@ bool Messenger::openLocalUrl(const QString &url, QVariant context) {
scope, scope,
callback, callback,
publicKey, publicKey,
payload, nonce,
errors)); errors));
return true; return true;
} }

View File

@ -228,6 +228,13 @@ QString ValidateUrl(const QString &url) {
} // namespace } // namespace
QString NonceNameByScope(const QString &scope) {
if (scope.startsWith('{') && scope.endsWith('}')) {
return qsl("nonce");
}
return qsl("payload");
}
bool ValueChanged(not_null<const Value*> value, const ValueMap &data) { bool ValueChanged(not_null<const Value*> value, const ValueMap &data) {
const auto FileChanged = [](const EditFile &file) { const auto FileChanged = [](const EditFile &file) {
if (file.uploadData) { if (file.uploadData) {
@ -271,13 +278,13 @@ FormRequest::FormRequest(
const QString &scope, const QString &scope,
const QString &callbackUrl, const QString &callbackUrl,
const QString &publicKey, const QString &publicKey,
const QString &payload, const QString &nonce,
const QString &errors) const QString &errors)
: botId(botId) : botId(botId)
, scope(scope) , scope(scope)
, callbackUrl(ValidateUrl(callbackUrl)) , callbackUrl(ValidateUrl(callbackUrl))
, publicKey(publicKey) , publicKey(publicKey)
, payload(payload) , nonce(nonce)
, errors(errors) { , errors(errors) {
} }
@ -654,7 +661,7 @@ auto FormController::prepareFinalData() -> FinalData {
auto json = QJsonObject(); auto json = QJsonObject();
if (errors.empty()) { if (errors.empty()) {
json.insert("secure_data", secureData); json.insert("secure_data", secureData);
json.insert("payload", _request.payload); json.insert(NonceNameByScope(_request.scope), _request.nonce);
} }
return { return {
@ -2151,9 +2158,9 @@ void FormController::suggestRestart() {
} }
void FormController::requestForm() { void FormController::requestForm() {
if (_request.payload.isEmpty()) { if (_request.nonce.isEmpty()) {
_formRequestId = -1; _formRequestId = -1;
formFail("PAYLOAD_EMPTY"); formFail(NonceNameByScope(_request.scope).toUpper() + "_EMPTY");
return; return;
} }
_formRequestId = request(MTPaccount_GetAuthorizationForm( _formRequestId = request(MTPaccount_GetAuthorizationForm(

View File

@ -31,6 +31,8 @@ struct SavedCredentials {
uint64 secretId = 0; uint64 secretId = 0;
}; };
QString NonceNameByScope(const QString &scope);
class ViewController; class ViewController;
struct FormRequest { struct FormRequest {
@ -39,14 +41,14 @@ struct FormRequest {
const QString &scope, const QString &scope,
const QString &callbackUrl, const QString &callbackUrl,
const QString &publicKey, const QString &publicKey,
const QString &payload, const QString &nonce,
const QString &errors); const QString &errors);
UserId botId; UserId botId;
QString scope; QString scope;
QString callbackUrl; QString callbackUrl;
QString publicKey; QString publicKey;
QString payload; QString nonce;
QString errors; QString errors;
}; };