Login failed for user token-identified principal. Token is expired

50 Views Asked by At

I have a singleton webjob hosted within Azure which is scheduled to run continuous mode type. In this web job, I have some database operations which are managed using EntityFramework. I am also using user-assigned ManagedIdentity to get the token from ManagedIdentityCredential which internally takes care of token refresh and passes it to the AccessToken property of the System.Data.Sqlclient SqlConnection. The token lifetime of the user assigned ManagedIdentity is 24 hours. For the first time the web job runs successfully without any issues, but on the subsequent iterations post 24 hours it breaks, since the token by that time has expired.

System.Data.EntityException: The underlying provider failed on Open. ---> System.Data.SqlClient.SqlException: Login failed for user ''. The token is expired.

Is there any method to auto-refresh tokens in the connection used by entity-framework included in .Net framework 4.6.2?

Is there any way we can use managed identity for the framework using System.data.sqlclient?

I tried passing the token to the System.Data.SqlClient SQL connection object and pass it to the EntityConnection which is used in ObjectContext to connect to SQL DB. But the token is expiring in this case.

0

There are 0 best solutions below