diff --git a/lib/src/base/parse_constants.dart b/lib/src/base/parse_constants.dart index cc3021fc2..554d633c9 100644 --- a/lib/src/base/parse_constants.dart +++ b/lib/src/base/parse_constants.dart @@ -44,6 +44,7 @@ const String keyHeaderContentType = 'Content-Type'; const String keyHeaderContentTypeJson = 'application/json'; const String keyHeaderMasterKey = 'X-Parse-Master-Key'; const String keyHeaderClientKey = 'X-Parse-Client-Key'; +const String keyHeaderInstallationId = 'X-Parse-Installation-Id'; // URL params const String keyParamSessionToken = 'sessionToken'; diff --git a/lib/src/objects/parse_user.dart b/lib/src/objects/parse_user.dart index f2f382343..e1b7c6d1b 100644 --- a/lib/src/objects/parse_user.dart +++ b/lib/src/objects/parse_user.dart @@ -126,11 +126,15 @@ class ParseUser extends ParseObject implements ParseCloneable { bodyData[keyVarPassword] = password; bodyData[keyVarUsername] = username; final Uri url = getSanitisedUri(_client, '$path'); + final Map headers = { + keyHeaderRevocableSession: '1', + }; + final String installationId = await _getInstallationId(); + if (installationId != null) { + headers[keyHeaderInstallationId] = installationId; + } final Response response = await _client.post(url, - headers: { - keyHeaderRevocableSession: '1', - }, - body: json.encode(bodyData)); + headers: headers, body: json.encode(bodyData)); return _handleResponse( this, response, ParseApiRQ.signUp, _debug, className); @@ -174,11 +178,15 @@ class ParseUser extends ParseObject implements ParseCloneable { try { final Uri url = getSanitisedUri(_client, '$keyEndPointUsers'); final Uuid uuid = Uuid(); - + final Map headers = { + keyHeaderRevocableSession: '1', + }; + final String installationId = await _getInstallationId(); + if (installationId != null) { + headers[keyHeaderInstallationId] = installationId; + } final Response response = await _client.post(url, - headers: { - keyHeaderRevocableSession: '1', - }, + headers: headers, body: jsonEncode({ 'authData': { 'anonymous': {'id': uuid.v4()} @@ -203,10 +211,15 @@ class ParseUser extends ParseObject implements ParseCloneable { Future _loginWith(String provider, Object authData) async { try { final Uri url = getSanitisedUri(_client, '$keyEndPointUsers'); + final Map headers = { + keyHeaderRevocableSession: '1', + }; + final String installationId = await _getInstallationId(); + if (installationId != null) { + headers[keyHeaderInstallationId] = installationId; + } final Response response = await _client.post(url, - headers: { - keyHeaderRevocableSession: '1', - }, + headers: headers, body: jsonEncode({ 'authData': {provider: authData} })); @@ -218,6 +231,12 @@ class ParseUser extends ParseObject implements ParseCloneable { } } + static Future _getInstallationId() async { + final ParseInstallation parseInstallation = + await ParseInstallation.currentInstallation(); + return parseInstallation?.installationId; + } + /// Sends a request to delete the sessions token from the /// server. Will also delete the local user data unless /// deleteLocalUserData is false.