DoInitialFileSystemConfiguration() public static method

public static DoInitialFileSystemConfiguration ( ) : void
return void
Exemplo n.º 1
0
        /// <summary>
        /// Logs the user in to the Realm Object Server.
        /// </summary>
        /// <param name="credentials">The credentials to use for authentication.</param>
        /// <param name="serverUri">The URI of the server that the user is authenticated against.</param>
        /// <returns>An awaitable Task, that, upon completion, contains the logged in user.</returns>
        public static async Task <User> LoginAsync(Credentials credentials, Uri serverUri)
        {
            Argument.NotNull(credentials, nameof(credentials));
            Argument.NotNull(serverUri, nameof(serverUri));
            Argument.Ensure(serverUri.Scheme.StartsWith("http"), "Unexpected protocol for login url. Expected http:// or https://.", nameof(serverUri));

            SharedRealmHandleExtensions.DoInitialFileSystemConfiguration();

            if (credentials.IdentityProvider == Credentials.Provider.AdminToken)
            {
                return(new User(SyncUserHandle.GetAdminTokenUser(serverUri.AbsoluteUri, credentials.Token)));
            }

            if (credentials.IdentityProvider == Credentials.Provider.CustomRefreshToken)
            {
                var userId  = (string)credentials.UserInfo[Credentials.Keys.Identity];
                var isAdmin = (bool)credentials.UserInfo[Credentials.Keys.IsAdmin];
                return(new User(SyncUserHandle.GetSyncUser(userId, serverUri.AbsoluteUri, credentials.Token, isAdmin)));
            }

            var result = await AuthenticationHelper.LoginAsync(credentials, serverUri);

            var handle = SyncUserHandle.GetSyncUser(result.UserId, serverUri.AbsoluteUri, result.RefreshToken, result.IsAdmin);

            return(new User(handle));
        }
Exemplo n.º 2
0
        /// <summary>
        /// Gets a logged in user with a specified identity.
        /// </summary>
        /// <returns>A user instance if a logged in user with that id exists, <c>null</c> otherwise.</returns>
        /// <param name="identity">The identity of the user.</param>
        /// <param name="serverUri">The URI of the server that the user is authenticated against.</param>
        public static User GetLoggedInUser(string identity, Uri serverUri)
        {
            SharedRealmHandleExtensions.DoInitialFileSystemConfiguration();

            if (SyncUserHandle.TryGetLoggedInUser(identity, serverUri.AbsoluteUri, out var userHandle))
            {
                return(new User(userHandle));
            }

            return(null);
        }
Exemplo n.º 3
0
        /// <summary>
        /// Gets a logged in user with a specified identity.
        /// </summary>
        /// <returns>A user instance if a logged in user with that id exists, <c>null</c> otherwise.</returns>
        /// <param name="identity">The identity of the user.</param>
        /// <param name="serverUrl">The URI of the server that the user is authenticated against.</param>
        public static User GetLoggedInUser(string identity, Uri serverUrl)
        {
            SharedRealmHandleExtensions.DoInitialFileSystemConfiguration();

            var handle = SyncUserHandle.GetLoggedInUser(identity, serverUrl.AbsoluteUri);

            if (handle == null)
            {
                return(null);
            }

            return(new User(handle));
        }
Exemplo n.º 4
0
        /// <summary>
        /// Logs the user in to the Realm Object Server.
        /// </summary>
        /// <param name="credentials">The credentials to use for authentication.</param>
        /// <param name="serverUrl">The URI of the server that the user is authenticated against.</param>
        /// <returns>An awaitable Task, that, upon completion, contains the logged in user.</returns>
        public static async Task <User> LoginAsync(Credentials credentials, Uri serverUrl)
        {
            SharedRealmHandleExtensions.DoInitialFileSystemConfiguration();

            if (credentials.IdentityProvider == Credentials.Providers.AccessToken)
            {
                var identity = (string)credentials.UserInfo[Credentials.Keys.Identity];
                var isAdmin  = (bool)credentials.UserInfo[Credentials.Keys.IsAdmin];
                return(new User(SyncUserHandle.GetSyncUser(identity, credentials.Token, serverUrl?.AbsoluteUri, isAdmin)));
            }

            var result = await AuthenticationHelper.Login(credentials, serverUrl);

            return(new User(SyncUserHandle.GetSyncUser(result.Item1, result.Item2, serverUrl.AbsoluteUri, isAdmin: false)));
        }