As the title says, I have a WEB APP MVC .NET Framework 4.7.2 to which I want to integrate Microsoft 365 functionalities. For this, I have already registered the app in Microsoft Entra ID
I can instantiate the Graph client in the HomeController through
var graphClient = this.GetGraphServiceClient();
From which I can hit the different endpoints I need without any problems.
var canales = await graphClient.Teams[XxTeam.Id]
.Channels
.GetAsync();
This is my configuration, notice I chose distributed token serialization with sql server.
Startup.cs
public void Configuration(IAppBuilder app)
{
try
{
app.SetDefaultSignInAsAuthenticationType(CookieAuthenticationDefaults.AuthenticationType);
app.UseCookieAuthentication(new CookieAuthenticationOptions());
OwinTokenAcquirerFactory factory = TokenAcquirerFactory.GetDefaultInstance<OwinTokenAcquirerFactory>();
app.AddMicrosoftIdentityWebApp(factory);
factory.Services
.Configure<ConfidentialClientApplicationOptions>(options => { })
.AddMicrosoftGraph()
.AddDistributedTokenCaches()
.Configure<MsalDistributedTokenCacheAdapterOptions>(options =>
{
options.DisableL1Cache = false;
})
.AddDistributedSqlServerCache(options =>
{
options.ConnectionString = "Data Source=xxx.xxx;Initial Catalog=...; Integrated Security=True;";
options.SchemaName = "dbo";
options.TableName = "TestCache";
});
factory.Build();
}
catch (Exception ex)
{
throw;
}
}
This worked a couple of times, I had tokens inserted in the suggested table (docs) when all of a sudden, it didn’t anymore. Tokens are no longer been inserted in the selected database anymore.
I don’t understand how can I debug this in a way to be able to detect if I’m making any mistake with the connectionString (which I doubt) or if I’m getting any exception.
I tried changing my connectionStrings in different ways, no luck so far.