/// <summary> /// Private method that invalidates the specified token and uses the OAuth2TokenReference /// if specified (instead of loading it from the store) /// </summary> /// <param name="accessToken"></param> /// <param name="reference"></param> /// <returns>The token deleted. The Username property will be null in this object</returns> private OAuth2AzureToken InvalidateToken(string accessToken, OAuth2TokenReference reference) { try { TableOperation op = TableOperation.Retrieve<OAuth2AzureTokenData>(accessToken, accessToken); TableResult result = table.Execute(op); OAuth2AzureTokenData token = result.Result as OAuth2AzureTokenData; if (token == null) return null; string consumerKey = token.ConsumerKey; string consumerSecret = token.ConsumerSecret; TableOperation delOp = TableOperation.Delete(token); table.Execute(delOp); if (reference == null) { op = TableOperation.Retrieve<OAuth2TokenReference>(consumerKey, consumerSecret); table.Execute(op); reference = result.Result as OAuth2TokenReference; } string username = null; if (reference != null) { username = reference.PartitionKey; delOp = TableOperation.Delete(reference); table.Execute(delOp); } return new OAuth2AzureToken(token, null); } catch (Exception ex) { Logger.Error("InvalidateToken Failed", ex); return null; } }
/// <summary> /// Writes the specified token to Azure Storage /// </summary> /// <param name="token">The token to save</param> /// <returns></returns> protected override bool SaveTokenToStore(OAuth2Token token) { try { TableOperation op = TableOperation.InsertOrReplace((OAuth2AzureTokenData)token.TokenData); table.Execute(op); OAuth2TokenReference reference = new OAuth2TokenReference(token.ConsumerKey, token.ConsumerSecret, token.AccessToken); TableOperation op2 = TableOperation.InsertOrReplace(reference); table.Execute(op2); return true; } catch (Exception ex) { Logger.Error("SaveToken Failed", ex); return false; } }