Reputation: 2267
I am developing solution where there are three webapi projcets. Each of them is secured with JWT tokens mechanism. So far webapis had not need to communicate. Finally they will be deployed on azure separetly and they will be using the same database.
I could generate a token with infinite lifespan and store it somewhere in the database, but something tells to me this is not right way to solve this issue.
Any help will be appreciated.
Question: How to allow them to communicate other way than generating a token with infinite lifespan?
Upvotes: 0
Views: 44
Reputation: 7910
Sounds like a use case for SQL Dependencies. An SQL dependency allows you to subscribe to an event that gets triggered when the result of a command differs. Something like so:
// I'll assume that a connection is already open
using (var command = new SqlCommand("SQL Command goes here")
{
var dependency = new SqlDependency(command);
dependency.OnChange += (object sender, SqlNotificationEventArgs e) =>
{
// Handle OnChange here
Console.WriteLine(e.Info);
}
// You can do all the things with the SQL Command here as you normally could
// for example execute it if it's a SELECT and read data
}
Be careful when using SQL dependencies as they're a bit more time consuming/ expensive as one would think, so try to keep them to a minimum
Upvotes: 1