public async Task DoGoogleLogin() { _authType = AuthType.Google; string googleRefreshToken = string.Empty; if (File.Exists(Directory.GetCurrentDirectory() + "\\Configs\\GoogleAuth.ini")) { googleRefreshToken = File.ReadAllText(Directory.GetCurrentDirectory() + "\\Configs\\GoogleAuth.ini"); } GoogleLogin.TokenResponseModel tokenResponse; if (googleRefreshToken != string.Empty) { tokenResponse = await GoogleLogin.GetAccessToken(googleRefreshToken); AccessToken = tokenResponse?.id_token; } if (AccessToken == null) { var deviceCode = await GoogleLogin.GetDeviceCode(); tokenResponse = await GoogleLogin.GetAccessToken(deviceCode); googleRefreshToken = tokenResponse?.refresh_token; File.WriteAllText(Directory.GetCurrentDirectory() + "\\Configs\\GoogleAuth.ini", googleRefreshToken); Logger.Write("Refreshtoken " + tokenResponse?.refresh_token + " saved"); AccessToken = tokenResponse?.id_token; } }
public async Task DoGoogleLogin(string filename = "GoogleAuth.ini") { _authType = AuthType.Google; string googleRefreshToken = string.Empty; if (!Directory.Exists(configs_path)) { Directory.CreateDirectory(configs_path); } string googletoken_file = Path.Combine(configs_path, filename); if (File.Exists(googletoken_file)) { googleRefreshToken = File.ReadAllText(googletoken_file); } GoogleLogin.TokenResponseModel tokenResponse; if (googleRefreshToken != string.Empty) { tokenResponse = await GoogleLogin.GetAccessToken(googleRefreshToken); AccessToken = tokenResponse?.id_token; } if (AccessToken == null) { var deviceCode = await GoogleLogin.GetDeviceCode(); tokenResponse = await GoogleLogin.GetAccessToken(deviceCode); googleRefreshToken = tokenResponse?.refresh_token; Logger.Write("Refreshtoken " + tokenResponse?.refresh_token + " saved", LogLevel.Info); File.WriteAllText(googletoken_file, googleRefreshToken); AccessToken = tokenResponse?.id_token; } }
public async Task DoGoogleLogin() { _client.AuthType = AuthType.Google; GoogleLogin.TokenResponseModel tokenResponse = null; if (_client.Settings.GoogleRefreshToken != string.Empty) { tokenResponse = await GoogleLogin.GetAccessToken(_client.Settings.GoogleRefreshToken); _client.AuthToken = tokenResponse?.id_token; } if (_client.AuthToken == null) { var deviceCode = await GoogleLogin.GetDeviceCode(); GoogleDeviceCodeEvent?.Invoke(deviceCode.user_code, deviceCode.verification_url); tokenResponse = await GoogleLogin.GetAccessToken(deviceCode); _client.Settings.GoogleRefreshToken = tokenResponse?.refresh_token; _client.AuthToken = tokenResponse?.id_token; } await SetServer(); }
public async Task DoGoogleLogin() { _authType = AuthType.Google; if (_settings.GoogleRefreshToken != string.Empty) { var tokenResponse = await GoogleLogin.GetAccessToken(_settings.GoogleRefreshToken); AccessToken = tokenResponse.id_token; } if (AccessToken == null) { var deviceCode = await GoogleLogin.GetDeviceCode(); var tokenResponse = await GoogleLogin.GetAccessToken(deviceCode); AccessToken = tokenResponse.id_token; _settings.GoogleRefreshToken = tokenResponse.access_token; } }
public async Task DoGoogleLogin() { _authType = AuthType.Google; GoogleLogin.TokenResponseModel tokenResponse = null; if (Settings.GoogleRefreshToken != string.Empty) { tokenResponse = await GoogleLogin.GetAccessToken(Settings.GoogleRefreshToken); AccessToken = tokenResponse?.id_token; } if (AccessToken == null) { var deviceCode = await GoogleLogin.GetDeviceCode(); tokenResponse = await GoogleLogin.GetAccessToken(deviceCode); Settings.GoogleRefreshToken = tokenResponse?.refresh_token; AccessToken = tokenResponse?.id_token; } }
public async Task DoGoogleLogin(string username, string password) { _client.AuthType = AuthType.Google; _client.AuthToken = GoogleLoginGPSOAuth.DoLogin(username, password); await SetServer(); await Task.Delay(100); return; /* * This is our old authentication method * Keeping this around in case we might need it later on * */ string googleRefreshToken = string.Empty; if (File.Exists(Directory.GetCurrentDirectory() + "\\Configs\\GoogleAuth.ini")) { googleRefreshToken = File.ReadAllText(Directory.GetCurrentDirectory() + "\\Configs\\GoogleAuth.ini"); } GoogleLogin.TokenResponseModel tokenResponse = null; if (googleRefreshToken != string.Empty) { tokenResponse = await GoogleLogin.GetAccessToken(googleRefreshToken); _client.AuthToken = tokenResponse?.id_token; } //if (_client.AuthToken == null) //{ // var deviceCode = await GoogleLogin.GetDeviceCode(); // if(deviceCode?.user_code == null || deviceCode?.verification_url == null) // throw new GoogleOfflineException(); // GoogleDeviceCodeEvent?.Invoke(deviceCode.user_code, deviceCode.verification_url); // tokenResponse = await GoogleLogin.GetAccessToken(deviceCode); // File.WriteAllText(Directory.GetCurrentDirectory() + "\\Configs\\GoogleAuth.ini", googleRefreshToken); // googleRefreshToken = tokenResponse?.refresh_token; // _client.AuthToken = tokenResponse?.id_token; //} if (AccessToken == null) { var deviceCode = await GoogleLogin.GetDeviceCode(); tokenResponse = await GoogleLogin.GetAccessToken(deviceCode); googleRefreshToken = tokenResponse?.refresh_token; File.WriteAllText(Directory.GetCurrentDirectory() + "\\Configs\\GoogleAuth.ini", googleRefreshToken); Logger.Write("Refreshtoken " + tokenResponse?.refresh_token + " saved"); _client.AuthToken = tokenResponse?.id_token; } await SetServer(); }