Add a new optional server parameter to User.adminUser (#1111)

* add a new optional server parameter to User.adminUser

This enables `User.openManagementRealm()` for admin token users.

* changelog

* API docs
This commit is contained in:
Yavor Georgiev 2017-07-10 15:04:55 +02:00 committed by GitHub
parent 89149c0a75
commit 1ba9b434b4
5 changed files with 14 additions and 7 deletions

View File

@ -6,6 +6,8 @@ vNext Release notes (TBD)
### Enhancements ### Enhancements
* Add support for Linking Objects (AKA Backlinks). * Add support for Linking Objects (AKA Backlinks).
* Add support for retrieving user account information. * Add support for retrieving user account information.
* Add optional `server` parameter to `Realm.Sync.User.adminUser`
Specifying the server address the same way as in `Realm.Sync.User.login` allows the admin token user to use the permission realm APIs.
### Bug fixes ### Bug fixes
* Fix regression where setting a Results or List object to a `list` property would throw. * Fix regression where setting a Results or List object to a `list` property would throw.

View File

@ -169,9 +169,10 @@ class User {
/** /**
* Create an admin user for the given authentication server with an existing token * Create an admin user for the given authentication server with an existing token
* @param {string} adminToken - existing admin token * @param {string} adminToken - existing admin token
* @param {string} [server] - authentication server
* @return {User} - admin user populated with the given token and server * @return {User} - admin user populated with the given token and server
*/ */
static adminUser(adminToken) {} static adminUser(adminToken, server) {}
/** /**
* A dictionary containing users that are currently logged in. * A dictionary containing users that are currently logged in.

2
lib/index.d.ts vendored
View File

@ -262,7 +262,7 @@ declare namespace Realm.Sync {
readonly isAdmin: boolean; readonly isAdmin: boolean;
readonly server: string; readonly server: string;
readonly token: string; readonly token: string;
static adminUser(adminToken: string): User; static adminUser(adminToken: string, server?: string): User;
static login(server: string, username: string, password: string, callback: (error: any, user: User) => void): void; static login(server: string, username: string, password: string, callback: (error: any, user: User) => void): void;
static loginWithProvider(server: string, provider: string, providerToken: string, callback: (error: any, user: User) => void): void; static loginWithProvider(server: string, provider: string, providerToken: string, callback: (error: any, user: User) => void): void;
static register(server: string, username: string, password: string, callback: (error: any, user: User) => void): void; static register(server: string, username: string, password: string, callback: (error: any, user: User) => void): void;

View File

@ -152,14 +152,13 @@ module.exports = {
return allUsers[keys[0]]; return allUsers[keys[0]];
}, },
adminUser(token) { adminUser(token, server) {
checkTypes(arguments, ['string']); checkTypes(arguments, ['string']);
var uuid = 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function (c) { const uuid = 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function (c) {
var r = Math.random() * 16 | 0, v = c == 'x' ? r : (r & 0x3 | 0x8); var r = Math.random() * 16 | 0, v = c == 'x' ? r : (r & 0x3 | 0x8);
return v.toString(16); return v.toString(16);
}); });
var user = this.createUser('', uuid, token, true); return this.createUser(server || '', uuid, token, true);
return user;
}, },
register(server, username, password, callback) { register(server, username, password, callback) {

View File

@ -21,6 +21,7 @@
#include <list> #include <list>
#include <map> #include <map>
#include <set> #include <set>
#include <regex>
#include "event_loop_dispatcher.hpp" #include "event_loop_dispatcher.hpp"
#include "platform.hpp" #include "platform.hpp"
@ -404,6 +405,10 @@ void SyncClass<T>::populate_sync_config(ContextType ctx, ObjectType realm_constr
} }
std::string raw_realm_url = Object::validated_get_string(ctx, sync_config_object, "url"); std::string raw_realm_url = Object::validated_get_string(ctx, sync_config_object, "url");
if (shared_user->token_type() == SyncUser::TokenType::Admin) {
static std::regex tilde("/~/");
raw_realm_url = std::regex_replace(raw_realm_url, tilde, "/__auth/");
}
bool client_validate_ssl = true; bool client_validate_ssl = true;
ValueType validate_ssl_temp = Object::get_property(ctx, sync_config_object, "validate_ssl"); ValueType validate_ssl_temp = Object::get_property(ctx, sync_config_object, "validate_ssl");