Search Results for

    Show / Hide Table of Contents

    Class User

    This class represents a user in a Atlas App Services application. The credentials are provided by various 3rd party providers (Facebook, Google, etc.). A user can log in to the 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.

    Inheritance
    Object
    User
    Implements
    IEquatable<User>
    Namespace: Realms.Sync
    Assembly: Realm.dll
    Syntax
    public class User : IEquatable<User>

    Properties

    | Improve this Doc View Source

    AccessToken

    Gets this user's access token. This is the user's credential for accessing MongoDB Atlas data and should be treated as sensitive information.

    Declaration
    public string AccessToken { get; }
    Property Value
    Type Description
    String

    A unique string that can be used to represent this user before the server.

    | Improve this Doc View Source

    ApiKeys

    Gets a User.ApiKeyClient instance that exposes functionality for managing user API keys.

    Declaration
    public User.ApiKeyClient ApiKeys { get; }
    Property Value
    Type Description
    User.ApiKeyClient

    A User.ApiKeyClient instance scoped to this User.

    See Also
    API Keys Authentication Docs
    | Improve this Doc View Source

    App

    Gets the app with which this user is associated.

    Declaration
    public App App { get; }
    Property Value
    Type Description
    App

    An App instance that owns this user.

    | Improve this Doc View Source

    DeviceId

    Gets a unique identifier for the device the user logged in to.

    Declaration
    public string DeviceId { get; }
    Property Value
    Type Description
    String

    A unique string that identifies the current device.

    | Improve this Doc View Source

    Functions

    Gets a User.FunctionsClient instance that exposes functionality for calling remote Atlas Functions.

    Declaration
    public User.FunctionsClient Functions { get; }
    Property Value
    Type Description
    User.FunctionsClient

    A User.FunctionsClient instance scoped to this User.

    See Also
    Functions Docs
    | Improve this Doc View Source

    Id

    Gets the Id of this user in Atlas App Services.

    Declaration
    public string Id { get; }
    Property Value
    Type Description
    String

    A string that uniquely identifies that user.

    | Improve this Doc View Source

    Identities

    Gets a collection of all identities associated with this user.

    Declaration
    public UserIdentity[] Identities { get; }
    Property Value
    Type Description
    UserIdentity[]

    The user's identities across different Credentials.AuthProviders.

    | Improve this Doc View Source

    Profile

    Gets the profile information for that user.

    Declaration
    public UserProfile Profile { get; }
    Property Value
    Type Description
    UserProfile

    A UserProfile object, containing information about the user's name, email, and so on.

    | Improve this Doc View Source

    Provider

    Gets a value indicating which Credentials.AuthProvider this user logged in with.

    Declaration
    public Credentials.AuthProvider Provider { get; }
    Property Value
    Type Description
    Credentials.AuthProvider

    The Credentials.AuthProvider used to login the user.

    | Improve this Doc View Source

    RefreshToken

    Gets this user's refresh token. This is the user's credential for accessing MongoDB Atlas data and should be treated as sensitive information.

    Declaration
    public string RefreshToken { get; }
    Property Value
    Type Description
    String

    A unique string that can be used for refreshing the user's credentials.

    | Improve this Doc View Source

    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 Source

    Equals(User)

    Determines whether this instance and another User instance are equal by comparing their identities.

    Declaration
    public bool Equals(User other)
    Parameters
    Type Name Description
    User other

    The User instance to compare with.

    Returns
    Type Description
    Boolean

    true if the two instances are equal; false otherwise.

    | Improve this Doc View Source

    GetCustomData()

    Gets the custom user data associated with this user in the Realm app.

    Declaration
    public BsonDocument GetCustomData()
    Returns
    Type Description
    MongoDB.Bson.BsonDocument

    A document containing the user data.

    Remarks

    The data is only refreshed when the user's access token is refreshed or when explicitly calling RefreshCustomDataAsync().

    See Also
    Custom User Data Docs
    | Improve this Doc View Source

    GetCustomData<T>()

    Gets the custom user data associated with this user in the Realm app and parses it to the specified type.

    Declaration
    public T GetCustomData<T>()
        where T : class
    Returns
    Type Description
    T

    A document containing the user data.

    Type Parameters
    Name Description
    T

    The managed type that matches the shape of the custom data documents.

    Remarks

    The data is only refreshed when the user's access token is refreshed or when explicitly calling RefreshCustomDataAsync().

    See Also
    Custom User Data Docs
    | Improve this Doc View Source

    GetMongoClient(String)

    Gets a MongoClient instance for accessing documents in a MongoDB database.

    Declaration
    public MongoClient GetMongoClient(string serviceName)
    Parameters
    Type Name Description
    String serviceName

    The name of the service as configured on the server.

    Returns
    Type Description
    MongoClient

    A MongoClient instance that can interact with the databases exposed in the remote service.

    | Improve this Doc View Source

    GetPushClient(String)

    Gets a client for interacting the with Firebase Cloud Messaging service exposed in Atlas App Services.

    Declaration
    [Obsolete("The push notifications functionality has been deprecated: https://www.mongodb.com/docs/atlas/app-services/reference/push-notifications/")]
    public User.PushClient GetPushClient(string serviceName)
    Parameters
    Type Name Description
    String serviceName

    The name of the service as configured in the App Services UI.

    Returns
    Type Description
    User.PushClient

    A client that exposes API to register/deregister push notification tokens.

    Remarks

    The FCM service needs to be configured and enabled in the App Services UI before devices can register and receive push notifications.

    See Also
    Send Mobile Push Notifications Docs
    | Improve this Doc View Source

    LinkCredentialsAsync(Credentials)

    Links the current user with a new user identity represented by the given credentials.

    Declaration
    public async Task<User> LinkCredentialsAsync(Credentials credentials)
    Parameters
    Type Name Description
    Credentials credentials

    The credentials to link with the current user.

    Returns
    Type Description
    Task<User>

    An awaitable Task<TResult> representing the remote link credentials operation. Upon successful completion, the task result will contain the user to which the credentials were linked.

    Remarks

    Linking a user with more credentials, mean the user can login either of these credentials. It also makes it possible to "upgrade" an anonymous user by linking it with e.g. Email/Password credentials.
    Note: It is not possible to link two existing users of Atlas App Services. The provided credentials must not have been used by another user.
    Note for email/password auth: To link a user with a new set of EmailPassword(String, String) credentials, you will need to first register these credentials by calling RegisterUserAsync(String, String).

    Examples

    The following snippet shows how to associate an email and password with an anonymous user allowing them to login on a different device.

    var app = App.Create("app-id")
    var user = await app.LogInAsync(Credentials.Anonymous());
    
    // This step is only needed for email password auth - a password record must exist
    // before you can link a user to it.
    await app.EmailPasswordAuth.RegisterUserAsync("email", "password");
    await user.LinkCredentialsAsync(Credentials.EmailPassword("email", "password"));
    | Improve this Doc View Source

    LogOutAsync()

    Removes the user's local credentials and attempts to invalidate their refresh token from the server.

    Declaration
    public Task LogOutAsync()
    Returns
    Type Description
    Task

    An awaitable Task that represents the remote logout operation.

    | Improve this Doc View Source

    RefreshCustomDataAsync()

    Re-fetch the user's custom data from the server.

    Declaration
    public async Task<BsonDocument> RefreshCustomDataAsync()
    Returns
    Type Description
    Task<MongoDB.Bson.BsonDocument>

    An awaitable Task<TResult> that represents the remote refresh operation. The result is a MongoDB.Bson.BsonDocument containing the updated custom user data. The value returned by GetCustomData() will also be updated with the new information.

    | Improve this Doc View Source

    RefreshCustomDataAsync<T>()

    Re-fetch the user's custom data from the server.

    Declaration
    public async Task<T> RefreshCustomDataAsync<T>()
        where T : class
    Returns
    Type Description
    Task<T>

    An awaitable Task<TResult> that represents the remote refresh operation. The result is an object containing the updated custom user data. The value returned by GetCustomData<T>() will also be updated with the new information.

    Type Parameters
    Name Description
    T

    The managed type that matches the shape of the custom data documents.

    | Improve this Doc View Source

    ToString()

    Declaration
    public override string ToString()
    Returns
    Type Description
    String
    Overrides
    Object.ToString()

    Operators

    | Improve this Doc View Source

    Equality(User, User)

    Declaration
    public static bool operator ==(User user1, User user2)
    Parameters
    Type Name Description
    User user1
    User user2
    Returns
    Type Description
    Boolean
    | Improve this Doc View Source

    Inequality(User, User)

    Declaration
    public static bool operator !=(User user1, User user2)
    Parameters
    Type Name Description
    User user1
    User user2
    Returns
    Type Description
    Boolean

    Implements

    System.IEquatable<T>
    • Improve this Doc
    • View Source
    In This Article
    Back to top Copyright © 2020 Realm
    Generated by DocFX