Skip to content

Make automatic sending of sessionId optional. #81

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 17, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 8 additions & 3 deletions lib/parse_server_sdk.dart
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ class Parse {
String clientKey,
String masterKey,
String sessionId,
bool autoSendSessionId,
SecurityContext securityContext}) {
ParseCoreData.init(appId, serverUrl,
debug: debug,
Expand All @@ -87,6 +88,7 @@ class Parse {
masterKey: masterKey,
clientKey: clientKey,
sessionId: sessionId,
autoSendSessionId: autoSendSessionId,
securityContext: securityContext);

_hasBeenInitialized = true;
Expand All @@ -97,12 +99,15 @@ class Parse {
bool hasParseBeenInitialized() => _hasBeenInitialized;

Future<ParseResponse> healthCheck(
{bool debug, ParseHTTPClient client}) async {
{bool debug, ParseHTTPClient client, bool autoSendSessionId}) async {
ParseResponse parseResponse;

bool _debug = isDebugEnabled(objectLevelDebug: debug);
ParseHTTPClient _client =
client ?? ParseHTTPClient(ParseCoreData().securityContext);
ParseHTTPClient _client = client ??
ParseHTTPClient(
autoSendSessionId:
autoSendSessionId ?? ParseCoreData().autoSendSessionId,
securityContext: ParseCoreData().securityContext);

try {
var response =
Expand Down
4 changes: 4 additions & 0 deletions lib/src/data/parse_core_data.dart
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ class ParseCoreData {
masterKey,
clientKey,
sessionId,
autoSendSessionId,
securityContext}) {
_instance = ParseCoreData._init(appId, serverUrl);

Expand All @@ -26,6 +27,8 @@ class ParseCoreData {
if (clientKey != null) _instance.clientKey = clientKey;
if (masterKey != null) _instance.masterKey = masterKey;
if (sessionId != null) _instance.sessionId = sessionId;
if (autoSendSessionId != null)
_instance.autoSendSessionId = autoSendSessionId;
if (securityContext != null) _instance.securityContext = securityContext;
}

Expand All @@ -36,6 +39,7 @@ class ParseCoreData {
String masterKey;
String clientKey;
String sessionId;
bool autoSendSessionId;
SecurityContext securityContext;
bool debug;
SharedPreferences storage;
Expand Down
10 changes: 7 additions & 3 deletions lib/src/network/parse_http_client.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,15 @@ part of flutter_parse_sdk;
/// Creates a custom version of HTTP Client that has Parse Data Preset
class ParseHTTPClient extends BaseClient {
final Client _client;
final bool _autoSendSessionId;
final String _userAgent = "$keyLibraryName $keySdkVersion";
ParseCoreData data = ParseCoreData();
Map<String, String> additionalHeaders;

ParseHTTPClient([SecurityContext securityContext])
: _client = securityContext != null
ParseHTTPClient(
{bool autoSendSessionId = false, SecurityContext securityContext})
: _autoSendSessionId = autoSendSessionId,
_client = securityContext != null
? IOClient(HttpClient(context: securityContext))
: IOClient();

Expand All @@ -17,7 +20,8 @@ class ParseHTTPClient extends BaseClient {
Future<StreamedResponse> send(BaseRequest request) {
request.headers[keyHeaderUserAgent] = _userAgent;
request.headers[keyHeaderApplicationId] = data.applicationId;
if ((data.sessionId != null) &&
if ((_autoSendSessionId == true) &&
(data.sessionId != null) &&
(request.headers[keyHeaderSessionToken] == null))
request.headers[keyHeaderSessionToken] = data.sessionId;

Expand Down
9 changes: 7 additions & 2 deletions lib/src/objects/parse_config.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,14 @@ part of flutter_parse_sdk;

class ParseConfig extends ParseObject {
/// Creates an instance of ParseConfig so that you can grab all configs from the server
ParseConfig({bool debug, ParseHTTPClient client}) : super('config') {
ParseConfig({bool debug, ParseHTTPClient client, bool autoSendSessionId})
: super('config') {
_debug = isDebugEnabled(objectLevelDebug: debug);
_client = client ?? ParseHTTPClient(ParseCoreData().securityContext);
_client = client ??
ParseHTTPClient(
autoSendSessionId:
autoSendSessionId ?? ParseCoreData().autoSendSessionId,
securityContext: ParseCoreData().securityContext);
}

/// Gets all configs from the server
Expand Down
12 changes: 10 additions & 2 deletions lib/src/objects/parse_file.dart
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,18 @@ class ParseFile extends ParseObject {
///
/// {https://docs.parseplatform.org/rest/guide/#files/}
ParseFile(this.file,
{String name, String url, bool debug, ParseHTTPClient client})
{String name,
String url,
bool debug,
ParseHTTPClient client,
bool autoSendSessionId})
: super(keyFile) {
_debug = isDebugEnabled(objectLevelDebug: debug);
_client = client ?? ParseHTTPClient(ParseCoreData().securityContext);
_client = client ??
ParseHTTPClient(
autoSendSessionId:
autoSendSessionId ?? ParseCoreData().autoSendSessionId,
securityContext: ParseCoreData().securityContext);

if (file != null) {
this.name = path.basename(file.path);
Expand Down
9 changes: 7 additions & 2 deletions lib/src/objects/parse_function.dart
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,17 @@ class ParseCloudFunction extends ParseObject {
/// Creates a new cloud function object
///
/// {https://docs.parseplatform.org/cloudcode/guide/}
ParseCloudFunction(this.functionName, {bool debug, ParseHTTPClient client})
ParseCloudFunction(this.functionName,
{bool debug, ParseHTTPClient client, bool autoSendSessionId})
: super(functionName) {
_path = "/functions/$functionName";

_debug = isDebugEnabled(objectLevelDebug: debug);
_client = client ?? ParseHTTPClient(ParseCoreData().securityContext);
_client = client ??
ParseHTTPClient(
autoSendSessionId:
autoSendSessionId ?? ParseCoreData().autoSendSessionId,
securityContext: ParseCoreData().securityContext);
}

/// Executes a cloud function
Expand Down
9 changes: 7 additions & 2 deletions lib/src/objects/parse_geo_point.dart
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,18 @@ class ParseGeoPoint extends ParseObject {
{double latitude = 0.0,
double longitude = 0.0,
bool debug,
ParseHTTPClient client})
ParseHTTPClient client,
bool autoSendSessionId})
: super(keyGeoPoint) {
_latitude = latitude;
_longitude = longitude;

_debug = isDebugEnabled(objectLevelDebug: debug);
_client = client ?? ParseHTTPClient(ParseCoreData().securityContext);
_client = client ??
ParseHTTPClient(
autoSendSessionId:
autoSendSessionId ?? ParseCoreData().autoSendSessionId,
securityContext: ParseCoreData().securityContext);
}

double get latitude => _latitude;
Expand Down
9 changes: 7 additions & 2 deletions lib/src/objects/parse_object.dart
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,18 @@ class ParseObject extends ParseBase implements ParseCloneable {
/// [String] className refers to the Table Name in your Parse Server,
/// [bool] debug will overwrite the current default debug settings and
/// [ParseHttpClient] can be overwritten to create your own HTTP Client
ParseObject(String className, {bool debug: false, ParseHTTPClient client})
ParseObject(String className,
{bool debug: false, ParseHTTPClient client, bool autoSendSessionId})
: super() {
setClassName(className);
_path = "$keyEndPointClasses$className";

_debug = isDebugEnabled(objectLevelDebug: debug);
_client = client ?? ParseHTTPClient(ParseCoreData().securityContext);
_client = client ??
ParseHTTPClient(
autoSendSessionId:
autoSendSessionId ?? ParseCoreData().autoSendSessionId,
securityContext: ParseCoreData().securityContext);
}

String toPointer() => parseEncode(this);
Expand Down
17 changes: 12 additions & 5 deletions lib/src/objects/parse_user.dart
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,10 @@ class ParseUser extends ParseObject implements ParseCloneable {
{bool debug, ParseHTTPClient client})
: super(keyClassUser) {
_debug = isDebugEnabled(objectLevelDebug: debug);
_client = client ?? ParseHTTPClient(ParseCoreData().securityContext);
_client = client ??
ParseHTTPClient(
autoSendSessionId: true,
securityContext: ParseCoreData().securityContext);

this.username = username;
this.password = password;
Expand All @@ -65,8 +68,10 @@ class ParseUser extends ParseObject implements ParseCloneable {
static Future<ParseResponse> getCurrentUserFromServer(
{String token, bool debug, ParseHTTPClient client}) async {
bool _debug = isDebugEnabled(objectLevelDebug: debug);
ParseHTTPClient _client =
client ?? ParseHTTPClient(ParseCoreData().securityContext);
ParseHTTPClient _client = client ??
ParseHTTPClient(
autoSendSessionId: true,
securityContext: ParseCoreData().securityContext);

// We can't get the current user and session without a sessionId
if ((ParseCoreData().sessionId == null) && (token == null)) {
Expand Down Expand Up @@ -272,8 +277,10 @@ class ParseUser extends ParseObject implements ParseCloneable {
var emptyUser = ParseUser(null, null, null);

bool _debug = isDebugEnabled(objectLevelDebug: debug);
ParseHTTPClient _client =
client ?? ParseHTTPClient(ParseCoreData().securityContext);
ParseHTTPClient _client = client ??
ParseHTTPClient(
autoSendSessionId: true,
securityContext: ParseCoreData().securityContext);

try {
final response = await _client.get("${ParseCoreData().serverUrl}/$path");
Expand Down