diff --git a/lib/src/enums/parse_enum_api_rq.dart b/lib/src/enums/parse_enum_api_rq.dart index 6b6f2b338..ea0b9b15d 100644 --- a/lib/src/enums/parse_enum_api_rq.dart +++ b/lib/src/enums/parse_enum_api_rq.dart @@ -14,6 +14,7 @@ enum ParseApiRQ { login, logout, loginAnonymous, + loginWith, verificationEmailRequest, requestPasswordReset, destroy, diff --git a/lib/src/objects/parse_user.dart b/lib/src/objects/parse_user.dart index 7c7b05e7f..b773431a4 100644 --- a/lib/src/objects/parse_user.dart +++ b/lib/src/objects/parse_user.dart @@ -62,7 +62,7 @@ class ParseUser extends ParseObject implements ParseCloneable { ParseUser.forQuery() : super(keyClassUser); - createUser(String username, String password, [String emailAddress]) { + static createUser([String username, String password, String emailAddress]) { return ParseUser(username, password, emailAddress); } @@ -206,6 +206,44 @@ class ParseUser extends ParseObject implements ParseCloneable { } } + // Logs in a user using a service + static Future loginWith(String provider, Object authData) async { + ParseUser user = ParseUser.createUser(); + var response = await user._loginWith(provider, authData); + if (response.success) { + return user; + } else { + return Future.error(response); + } + } + + Future _loginWith(String provider, Object authData) async { + try { + Uri tempUri = Uri.parse(_client.data.serverUrl); + + Uri url = Uri( + scheme: tempUri.scheme, + host: tempUri.host, + path: "${tempUri.path}$keyEndPointUsers", + ); + + final response = await _client.post(url, + headers: { + keyHeaderRevocableSession: "1", + }, + body: jsonEncode({ + "authData": { + provider: authData + } + })); + + return _handleResponse( + this, response, ParseApiRQ.loginWith, _debug, className); + } on Exception catch (e) { + return _handleException(e, ParseApiRQ.loginWith, _debug, className); + } + } + /// Sends a request to delete the sessions token from the /// server. Will also delete the local user data unless /// deleteLocalUserData is false. diff --git a/pubspec.yaml b/pubspec.yaml index 93c7c4254..7eb38c1e9 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -16,7 +16,7 @@ dependencies: http: ^0.12.0 # Utils - shared_preferences: ^0.4.3 + shared_preferences: ^0.5.0 path_provider: ^0.4.1 uuid: ^1.0.3