Skip to content

Commit 0d98007

Browse files
Merge branch '134-jwt-and-multi-credentials' into 'main'
Support JWT and multiple credentials #134 See merge request objectbox/objectbox-dart!99
2 parents 72397ca + 8cc0c4d commit 0d98007

File tree

21 files changed

+1087
-88
lines changed

21 files changed

+1087
-88
lines changed

dev-doc/updating-c-library.md

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -19,61 +19,61 @@ for the binding update script (see below) and
1919
for Flutter (`flutter_libs` and `sync_flutter_libs` plugins) on Linux and Windows:
2020

2121
```bash
22-
./tool/set-c-version.sh 4.0.2
22+
./tool/set-c-version.sh 4.1.0
2323
```
2424

2525
```text
26-
* Flutter for Linux/Windows, Dart Native: update to [objectbox-c 4.0.2](https://github.com/objectbox/objectbox-c/releases/tag/v4.0.2).
26+
* Flutter for Linux/Windows, Dart Native: update to [objectbox-c 4.1.0](https://github.com/objectbox/objectbox-c/releases/tag/v4.1.0).
2727
```
2828

2929
```text
30-
Update C library [4.0.1 -> 4.0.2]
30+
Update C library [4.0.2 -> 4.1.0]
3131
```
3232

3333
### Android
3434

3535
For the Flutter plugins on Android ([view releases](https://github.com/objectbox/objectbox-java/releases)):
3636

3737
```bash
38-
./tool/set-android-version.sh 4.0.3
38+
./tool/set-android-version.sh 4.1.0
3939
```
4040

4141
```text
42-
* Flutter for Android: update to [objectbox-android 4.0.3](https://github.com/objectbox/objectbox-java/releases/tag/V4.0.3).
42+
* Flutter for Android: update to [objectbox-android 4.1.0](https://github.com/objectbox/objectbox-java/releases/tag/V4.1.0).
4343
If your project is [using Admin](https://docs.objectbox.io/data-browser#admin-for-android), make sure to
44-
update to `io.objectbox:objectbox-android-objectbrowser:4.0.3` in `android/app/build.gradle`.
44+
update to `io.objectbox:objectbox-android-objectbrowser:4.1.0` in `android/app/build.gradle`.
4545
```
4646

4747
```text
48-
Update objectbox-android [4.0.2 -> 4.0.3]
48+
Update objectbox-android [4.0.3 -> 4.1.0]
4949
50-
Bundled with C API 4.0.1 and ObjectBox 4.0.2-2024-10-15
50+
Bundled with C API 4.1.0 and ObjectBox 4.1.0-2025-01-28
5151
```
5252

5353
Note: the embedded C API and ObjectBox version can be looked up
54-
from the relevant objectbox repository release tag (like `java-4.0.3`).
54+
from the relevant objectbox repository release tag (like `java-4.1.0`).
5555

5656
### Apple OSs
5757

5858
For the Flutter plugins on iOS/macOS ([view releases](https://github.com/objectbox/objectbox-swift/releases))
5959

6060
```bash
61-
./tool/set-swift-version.sh 4.0.1
61+
./tool/set-swift-version.sh 4.1.0
6262
```
6363

6464
```text
65-
* Flutter for iOS/macOS: update to [objectbox-swift 4.0.1](https://github.com/objectbox/objectbox-swift/releases/tag/v4.0.1).
65+
* Flutter for iOS/macOS: update to [objectbox-swift 4.1.0](https://github.com/objectbox/objectbox-swift/releases/tag/v4.1.0).
6666
For existing projects, run `pod repo update` and `pod update ObjectBox` in the `ios` or `macos` directories.
6767
```
6868

6969
```text
7070
Update ObjectBox Swift [4.0.0 -> 4.0.1]
7171
72-
Bundled with C API 4.0.2 and ObjectBox 4.0.2-2024-10-15
72+
Bundled with C API 4.1.0 and ObjectBox 4.1.0-2025-01-30
7373
```
7474

7575
Note: the embedded C API and ObjectBox version can be looked up
76-
from the objectbox-swift release tag (like `v4.0.1`) and
76+
from the objectbox-swift release tag (like `v4.1.0`) and
7777
the objectbox commit it points to (see `external/objectbox`).
7878

7979
## Dart C API bindings
@@ -96,5 +96,5 @@ Then manually:
9696
- Commit as
9797

9898
```text
99-
Update C-API [4.0.1 -> 4.0.2]
99+
Update C-API [4.0.2 -> 4.1.0]
100100
```

flutter_libs/android/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,6 @@ android {
5252
// ObjectBox Android library that includes an ObjectBox C library version compatible with
5353
// the C API binding of the ObjectBox Dart package.
5454
// https://central.sonatype.com/search?q=g:io.objectbox%20objectbox-android
55-
implementation "io.objectbox:objectbox-android:4.0.3"
55+
implementation "io.objectbox:objectbox-android:4.1.0"
5656
}
5757
}

flutter_libs/ios/objectbox_flutter_libs.podspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ Pod::Spec.new do |s|
1818
s.source_files = 'Classes/**/*'
1919

2020
s.dependency 'Flutter'
21-
s.dependency 'ObjectBox', '4.0.1'
21+
s.dependency 'ObjectBox', '4.1.0'
2222

2323
# Flutter.framework does not contain a i386 slice.
2424
s.pod_target_xcconfig = { 'DEFINES_MODULE' => 'YES', 'EXCLUDED_ARCHS[sdk=iphonesimulator*]' => 'i386' }

flutter_libs/linux/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ target_link_libraries(${PLUGIN_NAME} PRIVATE PkgConfig::GTK)
4444
# ----------------------------------------------------------------------
4545
# Download and add objectbox-c prebuilt library.
4646

47-
set(OBJECTBOX_VERSION 4.0.2)
47+
set(OBJECTBOX_VERSION 4.1.0)
4848

4949
set(OBJECTBOX_ARCH ${CMAKE_SYSTEM_PROCESSOR})
5050
if (${OBJECTBOX_ARCH} MATCHES "x86_64")

flutter_libs/macos/objectbox_flutter_libs.podspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ Pod::Spec.new do |s|
1818
s.source_files = 'Classes/**/*'
1919

2020
s.dependency 'FlutterMacOS'
21-
s.dependency 'ObjectBox', '4.0.1'
21+
s.dependency 'ObjectBox', '4.1.0'
2222

2323
s.pod_target_xcconfig = { 'DEFINES_MODULE' => 'YES' }
2424
s.swift_version = '5.3'

flutter_libs/windows/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ set(objectbox_flutter_libs_bundled_libraries
5050
# ----------------------------------------------------------------------
5151
# Download and add objectbox-c prebuilt library.
5252

53-
set(OBJECTBOX_VERSION 4.0.2)
53+
set(OBJECTBOX_VERSION 4.1.0)
5454

5555
set(OBJECTBOX_ARCH ${CMAKE_SYSTEM_PROCESSOR})
5656
if (${OBJECTBOX_ARCH} MATCHES "AMD64")

install.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ set -eu
55
# It's important that the generated dart bindings and the c-api library version match. Dart won't error on C function
66
# signature mismatch, leading to obscure memory bugs.
77
# For how to upgrade the version see dev-doc/updating-c-library.md
8-
cLibVersion=4.0.2
8+
cLibVersion=4.1.0
99
os=$(uname)
1010
cLibArgs="$*"
1111

objectbox/CHANGELOG.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,17 @@
11
## latest
22

3+
* Flutter for Linux/Windows, Dart Native: update to [objectbox-c 4.1.0](https://github.com/objectbox/objectbox-c/releases/tag/v4.1.0).
4+
* Flutter for Android: update to [objectbox-android 4.1.0](https://github.com/objectbox/objectbox-java/releases/tag/V4.1.0).
5+
If your project is [using Admin](https://docs.objectbox.io/data-browser#admin-for-android), make sure to
6+
update to `io.objectbox:objectbox-android-objectbrowser:4.1.0` in `android/app/build.gradle`.
7+
* Flutter for iOS/macOS: update to [objectbox-swift 4.1.0](https://github.com/objectbox/objectbox-swift/releases/tag/v4.1.0).
8+
For existing projects, run `pod repo update` and `pod update ObjectBox` in the `ios` or `macos` directories.
9+
10+
### Sync
11+
12+
* Add [JWT authentication](https://sync.objectbox.io/sync-server-configuration/jwt-authentication).
13+
* Sync clients can send multiple credentials for login.
14+
315
## 4.0.3 (2024-10-17)
416

517
* Generator: replace cryptography library, allows to use newer versions of the transitive `js` dependency. [#638](https://github.com/objectbox/objectbox-dart/issues/638)

objectbox/example/flutter/objectbox_demo_relations/android/app/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,5 +82,5 @@ dependencies {
8282
// Add objectbox-android-objectbrowser only for debug builds.
8383
// Warning: when objectbox_flutter_libs updates check if version
8484
// needs update, e.g. check https://github.com/objectbox/objectbox-dart/releases.
85-
debugImplementation("io.objectbox:objectbox-android-objectbrowser:4.0.3")
85+
debugImplementation("io.objectbox:objectbox-android-objectbrowser:4.1.0")
8686
}

objectbox/lib/src/native/bindings/bindings.dart

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -94,15 +94,16 @@ ObjectBoxC? _tryObjectBoxLibFile() {
9494

9595
// Require the minimum C API version of all supported platform-specific
9696
// libraries.
97-
// Library | C API version | Core version
98-
// objectbox-c | 4.0.2 | 4.0.2-2024-10-15
99-
// ObjectBox Swift 4.0.1 | 4.0.2 | 4.0.2-2024-10-15
100-
// objectbox-android 4.0.3 | 4.0.1 | 4.0.2-2024-10-15
97+
// Library | C API | Core
98+
// ------------------------|-------|-----------------
99+
// objectbox-c | 4.1.0 | 4.1.0-2025-01-28
100+
// ObjectBox Swift 4.1.0 | 4.1.0 | 4.1.0-2025-01-30
101+
// objectbox-android 4.1.0 | 4.1.0 | 4.1.0-2025-01-28
101102
var _obxCminMajor = 4;
102-
var _obxCminMinor = 0;
103-
var _obxCminPatch = 1;
103+
var _obxCminMinor = 1;
104+
var _obxCminPatch = 0;
104105
// Require minimum core version guaranteeing actual C API availability.
105-
var _obxCoreMinVersion = "4.0.2-2024-10-15";
106+
var _obxCoreMinVersion = "4.1.0-2025-01-28";
106107

107108
bool _isSupportedVersion(ObjectBoxC obxc) {
108109
if (!obxc.version_is_at_least(_obxCminMajor, _obxCminMinor, _obxCminPatch)) {

objectbox/lib/src/native/bindings/objectbox-sync.h

Lines changed: 47 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2018-2024 ObjectBox Ltd. All rights reserved.
2+
* Copyright 2018-2025 ObjectBox Ltd. All rights reserved.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -34,7 +34,7 @@
3434
#include "objectbox.h"
3535

3636
#if defined(static_assert) || defined(__cplusplus)
37-
static_assert(OBX_VERSION_MAJOR == 4 && OBX_VERSION_MINOR == 0 && OBX_VERSION_PATCH == 2, // NOLINT
37+
static_assert(OBX_VERSION_MAJOR == 4 && OBX_VERSION_MINOR == 1 && OBX_VERSION_PATCH == 0, // NOLINT
3838
"Versions of objectbox.h and objectbox-sync.h files do not match, please update");
3939
#endif
4040

@@ -56,11 +56,19 @@ typedef struct OBX_sync OBX_sync;
5656
/// specifies a generic client-side credential type.
5757
typedef enum {
5858
OBXSyncCredentialsType_NONE = 1,
59-
OBXSyncCredentialsType_SHARED_SECRET = 2,
59+
OBXSyncCredentialsType_SHARED_SECRET = 2, ///< Deprecated, replaced by SHARED_SECRET_SIPPED
6060
OBXSyncCredentialsType_GOOGLE_AUTH = 3,
61-
OBXSyncCredentialsType_SHARED_SECRET_SIPPED = 4,
62-
OBXSyncCredentialsType_OBX_ADMIN_USER = 5,
63-
OBXSyncCredentialsType_USER_PASSWORD = 6,
61+
OBXSyncCredentialsType_SHARED_SECRET_SIPPED = 4, ///< Uses shared secret to create a hashed credential.
62+
OBXSyncCredentialsType_OBX_ADMIN_USER = 5, ///< ObjectBox admin users (username/password)
63+
OBXSyncCredentialsType_USER_PASSWORD = 6, ///< Generic credential type suitable for ObjectBox admin
64+
///< (and possibly others in the future)
65+
OBXSyncCredentialsType_JWT_ID = 7, ///< JSON Web Token (JWT): an ID token that typically provides identity
66+
///< information about the authenticated user.
67+
OBXSyncCredentialsType_JWT_ACCESS = 8, ///< JSON Web Token (JWT): an access token that is used to access resources.
68+
OBXSyncCredentialsType_JWT_REFRESH = 9, ///< JSON Web Token (JWT): a refresh token that is used to obtain a new
69+
///< access token.
70+
OBXSyncCredentialsType_JWT_CUSTOM = 10, ///< JSON Web Token (JWT): a token that is neither an ID, access,
71+
///< nor refresh token.
6472
} OBXSyncCredentialsType;
6573

6674
// TODO sync prefix
@@ -194,8 +202,11 @@ OBX_C_API OBX_sync* obx_sync_urls(OBX_store* store, const char* server_urls[], s
194202
OBX_C_API obx_err obx_sync_close(OBX_sync* sync);
195203

196204
/// Sets credentials to authenticate the client with the server.
197-
/// See OBXSyncCredentialsType for available options.
198-
/// The accepted OBXSyncCredentials type depends on your sync-server configuration.
205+
/// Any credentials that were set before are replaced;
206+
/// if you want to pass multiple credentials, use obx_sync_credentials_add() instead.
207+
/// If the client was waiting for credentials, this can trigger a reconnection/login attempt.
208+
/// @param type See OBXSyncCredentialsType for available options.
209+
/// The accepted OBXSyncCredentials type depends on your sync-server configuration.
199210
/// @param data may be NULL in combination with OBXSyncCredentialsType_NONE
200211
OBX_C_API obx_err obx_sync_credentials(OBX_sync* sync, OBXSyncCredentialsType type, const uint8_t* data, size_t size);
201212

@@ -207,6 +218,29 @@ OBX_C_API obx_err obx_sync_credentials(OBX_sync* sync, OBXSyncCredentialsType ty
207218
OBX_C_API obx_err obx_sync_credentials_user_password(OBX_sync* sync, OBXSyncCredentialsType type, const char* username,
208219
const char* password);
209220

221+
/// For authentication with multiple credentials, collect credentials by calling this function multiple times.
222+
/// When adding the last credentials element, the "complete" flag must be set to true.
223+
/// When completed, it will "activate" the collected credentials and replace any previously set credentials and
224+
/// potentially trigger a reconnection/login attempt.
225+
/// @param type See OBXSyncCredentialsType for available options.
226+
/// The accepted OBXSyncCredentials type depends on your sync-server configuration.
227+
/// @param data non-NULL (OBXSyncCredentialsType_NONE is not allowed)
228+
/// @param complete set to true when adding the last credentials element to activate the set of credentials
229+
OBX_C_API obx_err obx_sync_credentials_add(OBX_sync* sync, OBXSyncCredentialsType type, const uint8_t* data, size_t size,
230+
bool complete);
231+
232+
/// For authentication with multiple credentials, collect credentials by calling this function multiple times.
233+
/// When adding the last credentials element, the "complete" flag must be set to true.
234+
/// When completed, it will "activate" the collected credentials and replace any previously set credentials and
235+
/// potentially trigger a reconnection/login attempt.
236+
/// @param type See OBXSyncCredentialsType for available options.
237+
/// The accepted OBXSyncCredentials type depends on your sync-server configuration.
238+
/// @param username non-NULL
239+
/// @param password non-NULL
240+
/// @param complete set to true when adding the last credentials element to activate the set of credentials
241+
OBX_C_API obx_err obx_sync_credentials_add_user_password(OBX_sync* sync, OBXSyncCredentialsType type,
242+
const char* username, const char* password, bool complete);
243+
210244
/// Configures the maximum number of outgoing TX messages that can be sent without an ACK from the server.
211245
/// @returns OBX_ERROR_ILLEGAL_ARGUMENT if value is not in the range 1-20
212246
OBX_C_API obx_err obx_sync_max_messages_in_flight(OBX_sync* sync, int value);
@@ -374,9 +408,9 @@ OBX_C_API void obx_sync_listener_msg_objects(OBX_sync* sync, OBX_sync_listener_m
374408
void* listener_arg);
375409

376410
/// Set or overwrite a previously set 'error' listener - provides information about occurred sync-level errors.
377-
/// @param listener set NULL to reset
411+
/// @param listener The callback to receive sync errors. Set to NULL to reset.
378412
/// @param listener_arg is a pass-through argument passed to the listener
379-
OBX_C_API void obx_sync_listener_error(OBX_sync* sync, OBX_sync_listener_error* error, void* listener_arg);
413+
OBX_C_API void obx_sync_listener_error(OBX_sync* sync, OBX_sync_listener_error* listener, void* listener_arg);
380414

381415
//----------------------------------------------
382416
// Sync Stats
@@ -702,7 +736,7 @@ typedef enum {
702736

703737
/// Get u64 value for sync server statistics.
704738
/// @param counter_type the counter value to be read (make sure to choose a uint64_t (u64) metric value type).
705-
/// @param out_count receives the counter value.
739+
/// @param out_value receives the counter value.
706740
/// @return OBX_SUCCESS if the counter has been successfully retrieved.
707741
/// @return OBX_ERROR_ILLEGAL_ARGUMENT if counter_type is undefined (this also happens if the wrong type is requested)
708742
/// @return OBX_ERROR_ILLEGAL_STATE if the server is not started.
@@ -711,7 +745,7 @@ OBX_C_API obx_err obx_sync_server_stats_u64(OBX_sync_server* server, OBXSyncServ
711745

712746
/// Get double value for sync server statistics.
713747
/// @param counter_type the counter value to be read (make sure to use a double (f64) metric value type).
714-
/// @param out_count receives the counter value.
748+
/// @param out_value receives the counter value.
715749
/// @return OBX_SUCCESS if the counter has been successfully retrieved.
716750
/// @return OBX_ERROR_ILLEGAL_ARGUMENT if counter_type is undefined (this also happens if the wrong type is requested)
717751
/// @return OBX_ERROR_ILLEGAL_STATE if the server is not started.
@@ -785,7 +819,7 @@ typedef void OBX_custom_msg_server_func_client_connection_close(void* server_use
785819
/// Callback to shutdown and free all resources associated with the sync client connection to the custom server.
786820
/// Note that the custom server may already have been shutdown at this point (e.g. no server user data is supplied).
787821
/// Must be provided to implement a custom server. See notes on OBX_custom_msg_server_functions for more details.
788-
/// @param server_user_data User supplied data returned by the function that created the server
822+
/// @param connection_user_data User supplied data returned by the function that created the server
789823
typedef void OBX_custom_msg_server_func_client_connection_shutdown(void* connection_user_data);
790824

791825
/// Struct of the custom server function callbacks. In order to implement the custom server, you must provide

0 commit comments

Comments
 (0)