Azure-Samples / active-directory-dotnet-webapp-webapi-multitenant-openidconnect

A sample .NET 4.5 MVC SaaS web app that signs-up and signs-in users from any Azure AD tenant, and calls the Azure AD Graph API.
66 stars 45 forks source link

ADAL TokenCache based on Azure Sql Db #34

Closed rastogi-nitin closed 7 years ago

rastogi-nitin commented 7 years ago

I am trying to implement SQL Server caching for ADAL tokens following the approach in efadaltokencache. I have my database instance as an Azure SQL DB.

In order to implement, I created the necessary table with specified columns in SQL Server i.e. entryId (int), webUserUniqueId (nvarchar(max)), cacheBits(varbinary(max)) and lastWrite. For one, I didn't find the need to create this in the documentation of the sample, but if it's not there it needed to be created, so I created one.

Now, while saving the changes to the cache after a token has been generated, an event "AfterAccessNotification" is triggered to update the database. However, I am getting the exception on SaveChanges - "System.Data.SqlClient.SqlException: String or binary data would be truncated.The statement has been terminated."

Not sure what is it that I am missing?.

rastogi-nitin commented 7 years ago

Please ignore the issue. It was actually an issue with Azure SQL DB and VS 2017 interaction. One of my columns needed a change and I made that change, but seems like the change is not getting committed to the DB from VS's oob interaction with Azure Sql DB. Even if I recreated the table after dropping, for some reason, my changes were not picked. I changed the name and all's fine.