private void LocalStorageChanged(object?sender, ChangedEventArgs args) { if (args.Key != Constants.ACCESS_TOKEN_NAME) { return; } var isValidToken = CheckToken(); AuthStateChanged?.Invoke(this, isValidToken); }
private async Task HandleAuthStatePotentiallyChanged() { bool authGranted = (await IsValidAuthTokenPresent()); if (authGranted && (await GetAuthToken()) is string token) { dispatcher.Authorize(token); } if (authGranted != authGrantedWhenLastChecked) { Console.WriteLine($"Authorization state changed to: {authGranted}"); authGrantedWhenLastChecked = authGranted; AuthStateChanged?.Invoke(authGranted); } }
protected virtual void OnAuthStateChanged(UserAuthorizeEventArgs e) { EventHandler <UserAuthorizeEventArgs> temp = System.Threading.Volatile.Read(ref AuthStateChanged); AuthStateChanged?.Invoke(this, e); }
private async Task AuthorizationStateUpdateHandlerAsync(TdLib.TdApi.Update.UpdateAuthorizationState authUpdate) { switch (authUpdate.AuthorizationState) { case TdApi.AuthorizationState.AuthorizationStateWaitTdlibParameters _: string path = DataStorage.UserDataFolder; await _dialer.ExecuteAsync(new TdApi.SetTdlibParameters { Parameters = new TdApi.TdlibParameters { UseTestDc = false, DatabaseDirectory = path, // directory here FilesDirectory = path, // directory here UseFileDatabase = true, UseChatInfoDatabase = true, UseMessageDatabase = true, UseSecretChats = true, ApiId = _api_id, // your API ID ApiHash = _api_hash, // your API HASH SystemLanguageCode = "en", DeviceModel = "Desktop", SystemVersion = "0.1", ApplicationVersion = "0.1", EnableStorageOptimizer = true, IgnoreFileNames = false } }); break; case TdApi.AuthorizationState.AuthorizationStateWaitEncryptionKey _: await _dialer.ExecuteAsync(new TdApi.CheckDatabaseEncryptionKey()); break; case TdApi.AuthorizationState.AuthorizationStateWaitPhoneNumber _: AuthStateChanged?.Invoke(this, new AuthEventArgs() { State = AuthState.WaitPhoneNumber }); break; case TdApi.AuthorizationState.AuthorizationStateWaitCode _: AuthStateChanged?.Invoke(this, new AuthEventArgs() { State = AuthState.WaitCode }); break; case TdApi.AuthorizationState.AuthorizationStateWaitPassword _: await _dialer.ExecuteAsync(new TdApi.CheckAuthenticationPassword { Password = "******" // your password }); break; case TdApi.AuthorizationState.AuthorizationStateReady _: AuthStateChanged?.Invoke(this, new AuthEventArgs() { State = AuthState.Ready }); IsUserAuthorized = true; await GetChats(512); break; case TdApi.AuthorizationState.AuthorizationStateLoggingOut _: AuthStateChanged?.Invoke(this, new AuthEventArgs() { State = AuthState.LoggingOut }); break; case TdApi.AuthorizationState.AuthorizationStateClosing _: AuthStateChanged?.Invoke(this, new AuthEventArgs() { State = AuthState.Closing }); break; } }