Class User
This class represents a user on the Realm Object Server. The credentials are provided by various 3rd party providers (Facebook, Google, etc.). A user can log in to the Realm Object Server, and if access is granted, it is possible to synchronize the local and the remote Realm. Moreover, synchronization is halted when the user is logged out. It is possible to persist a user. By retrieving a user, there is no need to log in to the 3rd party provider again. Persisting a user between sessions, the user's credentials are stored locally on the device, and should be treated as sensitive data.
Inherited Members
Namespace:Realms.Sync
Assembly:Realm.Sync.dll
Syntax
public class User : IEquatable<User>
Properties
| Improve this Doc View SourceAllLoggedIn
Gets all currently logged in users.
Declaration
public static User[] AllLoggedIn { get; }
Property Value
| Type | Description |
|---|---|
| User[] | An array of valid logged in users. |
Current
Gets the currently logged-in user. If none exists, null is returned. If more than one user is currently logged in, an exception is thrown.
Declaration
public static User Current { get; }
Property Value
| Type | Description |
|---|---|
| User | Valid user or |
Exceptions
| Type | Condition |
|---|---|
| RealmException | Thrown if there are more than one users logged in. |
Identity
Gets the identity of this user on the Realm Object Server. The identity is a guaranteed to be unique among all users on the Realm Object Server.
Declaration
public string Identity { get; }
Property Value
| Type | Description |
|---|---|
| String | A string that uniquely identifies that user in Realm Object Server. |
RefreshToken
Gets this user's refresh token. This is the user's credential for accessing the Realm Object Server and should be treated as sensitive data.
Declaration
public string RefreshToken { get; }
Property Value
| Type | Description |
|---|---|
| String | A unique string that can be used for refreshing the user's credentials. |
ServerUri
Gets the server URI that was used for authentication.
Declaration
public Uri ServerUri { get; }
Property Value
| Type | Description |
|---|---|
| Uri | The Uri used to connect to the authentication service. |
State
Gets the current state of the user.
Declaration
public UserState State { get; }
Property Value
| Type | Description |
|---|---|
| UserState | A value indicating whether the user is active, logged out, or an error has occurred. |
Methods
| Improve this Doc View SourceConfigurePersistence(UserPersistenceMode, Byte[], Boolean)
Configures user persistence. If you need to call this, be sure to do so before accessing any other Realm API.
Declaration
public static void ConfigurePersistence(UserPersistenceMode mode, byte[] encryptionKey = null, bool resetOnError = false)
Parameters
| Type | Name | Description |
|---|---|---|
| UserPersistenceMode | mode | The persistence mode. |
| System.Byte[] | encryptionKey | The key to encrypt the persistent user store with. |
| Boolean | resetOnError | If set to |
Remarks
Users are persisted in a realm file within the application's sandbox.
By default User objects are persisted and are additionaly protected with an encryption key stored in the iOS Keychain when running on an iOS device (but not on a Simulator). On Android users are persisted in plaintext, because the AndroidKeyStore API is only supported on API level 18 and up. You might want to provide your own encryption key on Android or disable persistence for security reasons.
Equals(User)
Declaration
public bool Equals(User other)
Parameters
| Type | Name | Description |
|---|---|---|
| User | other |
Returns
| Type | Description |
|---|---|
| Boolean |
Implements
| Improve this Doc View SourceEquals(Object)
Declaration
public override bool Equals(object obj)
Parameters
| Type | Name | Description |
|---|---|---|
| Object | obj |
Returns
| Type | Description |
|---|---|
| Boolean |
Overrides
| Improve this Doc View SourceGetHashCode()
Declaration
public override int GetHashCode()
Returns
| Type | Description |
|---|---|
| Int32 |
Overrides
| Improve this Doc View SourceGetLoggedInUser(String)
Gets a logged in user with a specified identity.
Declaration
public static User GetLoggedInUser(string identity)
Parameters
| Type | Name | Description |
|---|---|---|
| String | identity | The identity of the user. |
Returns
| Type | Description |
|---|---|
| User | A user instance if a logged in user with that id exists, |
LoginAsync(Credentials, Uri)
Logs the user in to the Realm Object Server.
Declaration
public static Task<User> LoginAsync(Credentials credentials, Uri serverUrl)
Parameters
| Type | Name | Description |
|---|---|---|
| Credentials | credentials | The credentials to use for authentication. |
| Uri | serverUrl | The URI of the server that the user is authenticated against. |
Returns
| Type | Description |
|---|---|
| Task<User> | An awaitable Task, that, upon completion, contains the logged in user. |
LogOut()
Logs out the user from the Realm Object Server. Once the Object Server has confirmed the logout the user credentials will be deleted from this device.
Declaration
public void LogOut()