public void CheckForExistingToken(Core.DataStore.IRelationalDataStore <Token> tokenStore, ExecutionContext context, Guid providerId, StateObject stateObject, string accountId) { var tokenCheck = tokenStore.Select(context, t => t.ProviderId == providerId && t.AccountId == accountId && t.UserId == stateObject.UserId && t.ConfigurationId != null).ToList(); var providerEnabledCheck = tokenCheck.FirstOrDefault(); if (providerEnabledCheck != null) { if (providerEnabledCheck.ConfigurationId != null) { var organizationProviderDataStore = context.Organization.DataStores.GetDataStore <ProviderDefinition>(); var organizationProvider = organizationProviderDataStore.GetById(context, providerEnabledCheck.ConfigurationId.Value); if (organizationProvider != null) { if (organizationProvider.Approved == false) { if (tokenCheck.Any()) { //Delete the connected token tokenStore.Delete(context, tokenCheck); //Delete the thing the token is connected to organizationProviderDataStore.Delete(context, organizationProvider); } else { context.Log.Info(() => "Token found for GoToMeeting"); } } } } } }
public void NoAccountIdCheck(Core.DataStore.IRelationalDataStore <Token> tokenStore, ExecutionContext context, Guid providerId, StateObject stateObject) { var tokenCheck = tokenStore.Select(context, t => t.ProviderId == providerId && t.AccountId == null && t.UserId == stateObject.UserId).ToList(); //Delete a token if there is one for this provider that has not set an accountId for it yet. if (tokenCheck.Any()) { tokenStore.Delete(context, tokenCheck); context.Log.Info(() => "Deleting Token with no assocaited Organization Provider for GoToMeeting", tokenCheck.First().Id); } }