Skip to content

Commit

Permalink
Update custom function authentication to remove BSON
Browse files Browse the repository at this point in the history
  • Loading branch information
dacharyc committed Jan 8, 2024
1 parent f25afaa commit 6a33e5c
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 27 deletions.
34 changes: 16 additions & 18 deletions examples/cpp/sync/authentication.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,24 +53,22 @@ TEST_CASE("create and log in an anonymous user", "[realm][sync]") {
REQUIRE(user.access_token().empty());
}

// TODO: Figure out how to do this properly in the updated SDK
// TEST_CASE("test custom function authentication", "[realm][sync]") {
// // :snippet-start: custom-function
// // Custom function authentication takes a BSON Document with parameters.
// // The parameter details vary depending on how you define your custom
// authentication function. realm::bson::BsonDocument params = {{
// "username", "bob" }};

// auto appConfig = realm::App::configuration();
// appConfig.app_id = APP_ID;
// auto app = realm::App(appConfig);

// auto user = app.login(realm::App::credentials::function(params)).get();
// // :snippet-end:
// REQUIRE(!user.access_token().empty());
// user.log_out().get();
// REQUIRE(user.access_token().empty());
// }
TEST_CASE("test custom function authentication", "[realm][sync]") {
// :snippet-start: custom-function
auto appConfig = realm::App::configuration();
appConfig.app_id = APP_ID;
auto app = realm::App(appConfig);

/* Custom function authentication takes a string parameters argument.
The parameter details vary depending on how you define your custom
authentication function. */
std::string params = "{\"username\": \"bob\"}";
auto user = app.login(realm::App::credentials::function(params)).get();
// :snippet-end:
REQUIRE(!user.access_token().empty());
user.log_out().get();
REQUIRE(user.access_token().empty());
}

TEST_CASE("test get user access token", "[realm][sync]") {
auto appConfig = realm::App::configuration();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
// // Custom function authentication takes a BSON Document with parameters.
// // The parameter details vary depending on how you define your custom
// authentication function. realm::bson::BsonDocument params = {{
// "username", "bob" }};
auto appConfig = realm::App::configuration();
appConfig.app_id = APP_ID;
auto app = realm::App(appConfig);

// auto appConfig = realm::App::configuration();
// appConfig.app_id = APP_ID;
// auto app = realm::App(appConfig);

// auto user = app.login(realm::App::credentials::function(params)).get();
/* Custom function authentication takes a string parameters argument.
The parameter details vary depending on how you define your custom
authentication function. */
std::string params = "{\"username\": \"bob\"}";
auto user = app.login(realm::App::credentials::function(params)).get();

0 comments on commit 6a33e5c

Please sign in to comment.