private static IAuthorizationState GetAuthentication(NativeApplicationClient arg) { // Get the auth URL: IAuthorizationState state = new AuthorizationState(new[] { CalendarService.Scopes.Calendar.GetStringValue() }); state.Callback = new Uri(NativeApplicationClient.OutOfBandCallbackUrl); state.RefreshToken = Settings.Instance.RefreshToken; Uri authUri = arg.RequestUserAuthorization(state); IAuthorizationState result = null; if (state.RefreshToken == "") { // Request authorization from the user (by opening a browser window): Process.Start(authUri.ToString()); EnterAuthorizationCode eac = new EnterAuthorizationCode(); if (eac.ShowDialog() == DialogResult.OK) { // Retrieve the access/refresh tokens by using the authorization code: result = arg.ProcessUserAuthorization(eac.authcode, state); //save the refresh token for future use Settings.Instance.RefreshToken = result.RefreshToken; XMLManager.Export(Settings.Instance, MainForm.FILENAME); return(result); } else { return(null); } } else { arg.RefreshToken(state, null); result = state; return(result); } }
private static IAuthorizationState GetAuthentication(NativeApplicationClient arg) { // Get the auth URL: IAuthorizationState state = new AuthorizationState(new[] { CalendarService.Scopes.Calendar.GetStringValue() }); state.Callback = new Uri(NativeApplicationClient.OutOfBandCallbackUrl); state.RefreshToken = Settings.Instance.RefreshToken; Uri authUri = arg.RequestUserAuthorization(state); IAuthorizationState result = null; if (state.RefreshToken == "") { // Request authorization from the user (by opening a browser window): Process.Start(authUri.ToString()); EnterAuthorizationCode eac = new EnterAuthorizationCode(); if (eac.ShowDialog() == DialogResult.OK) { // Retrieve the access/refresh tokens by using the authorization code: result = arg.ProcessUserAuthorization(eac.authcode, state); //save the refresh token for future use Settings.Instance.RefreshToken = result.RefreshToken; XMLManager.export(Settings.Instance, MainForm.FILENAME); return result; } else { return null; } } else { arg.RefreshToken(state, null); result = state; return result; } }