/// <summary> /// This deletes this authentication tokens from persistent storage. Note this uses the data members from "this" object. It revokes the credentials then commits them. /// </summary> /// <returns></returns> async public Task <bool> unCommitAuthentication() { bool RetValue = false; UserCredential googleCredential = getGoogleOauthCredentials(); Object[] Param = { this.TilerID, this.Email, this.ProviderID }; try { await googleCredential.RefreshTokenAsync(System.Threading.CancellationToken.None).ConfigureAwait(false); await googleCredential.RevokeTokenAsync(System.Threading.CancellationToken.None).ConfigureAwait(false); RetValue = true; } catch (Exception e) { ; } finally { ApplicationDbContext db = new ApplicationDbContext(); ThirdPartyCalendarAuthenticationModel checkingThirdPartyCalendarAuthentication = db.ThirdPartyAuthentication.Find(Param); if (checkingThirdPartyCalendarAuthentication != null) { db.ThirdPartyAuthentication.Remove(checkingThirdPartyCalendarAuthentication); db.SaveChanges(); } } return(RetValue); }
//refreshes the token credentials and updates tiler DB with the data async public Task <bool> refreshAndCommitToken(ApplicationDbContext db) { bool RetValue = await refreshAuthenticationToken().ConfigureAwait(false); if (RetValue) { Object[] Param = { this.TilerID, this.Email, this.ProviderID }; ThirdPartyCalendarAuthenticationModel checkingThirdPartyCalendarAuthentication = await db.ThirdPartyAuthentication.FindAsync(Param); if (checkingThirdPartyCalendarAuthentication != null) { checkingThirdPartyCalendarAuthentication.ID = this.ID; checkingThirdPartyCalendarAuthentication.Token = this.Token; checkingThirdPartyCalendarAuthentication.RefreshToken = this.RefreshToken; checkingThirdPartyCalendarAuthentication.Deadline = this.Deadline; db.Entry(checkingThirdPartyCalendarAuthentication).State = EntityState.Modified; await db.SaveChangesAsync().ConfigureAwait(false); } else { db.ThirdPartyAuthentication.Add(this); await db.SaveChangesAsync(); } } return(RetValue); }
public GoogleTilerEventControl(TilerFront.Models.ThirdPartyCalendarAuthenticationModel AuthenticationCredential, ApplicationDbContext db) { CalendarServiceInfo = new Google.Apis.Calendar.v3.CalendarService(new BaseClientService.Initializer { HttpClientInitializer = AuthenticationCredential.getGoogleOauthCredentials(), ApplicationName = applicationName }); AuthenticationInfo = AuthenticationCredential; EmailID = AuthenticationCredential.Email; this.db = db; }
public IndexedThirdPartyAuthentication(ThirdPartyCalendarAuthenticationModel AuthenticationData, uint OrderIndex) { ThirdPartyIndex = OrderIndex; ID = AuthenticationData.ID; TilerID = AuthenticationData.TilerID; isLongLived = AuthenticationData.isLongLived; Email = AuthenticationData.Email; Token = AuthenticationData.Token; RefreshToken = AuthenticationData.RefreshToken; ProviderID = AuthenticationData.ProviderID; Deadline = AuthenticationData.Deadline; DefaultLocation = AuthenticationData.DefaultLocation; DefaultLocationId = AuthenticationData.DefaultLocationId; }