Azure.Identity.CredentialUnavailableException using middletier localhost for XAF Winforms - Stack Overflow

I want to upgrade my XAF 24.1.6 Winforms application to use middletier security and connect to a databa

I want to upgrade my XAF 24.1.6 Winforms application to use middletier security and connect to a database in Azure.

I managed to get "Hello Middle Tier" working with the database. However the full application has many more features.

I copied the working Middle Tier to my full application but when I run it I get the following

I see the middle tier url has not quite loaded when I get the error, causing me to wonder if it is a timing issue.

The call stack is

System.Private.CoreLib.dll!System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
Azure.Identity.dll!Azure.Identity.CredentialDiagnosticScope.FailWrapAndThrow(System.Exception ex, string additionalMessage, bool isCredentialUnavailable) Line 45
    at Azure.Identity\CredentialDiagnosticScope.cs(45)
Azure.Identity.dll!Azure.Identity.EnvironmentCredential.GetTokenImplAsync(bool async, Azure.Core.TokenRequestContext requestContext, System.Threading.CancellationToken cancellationToken) Line 87
    at Azure.Identity\EnvironmentCredential.cs(87)
Azure.Identity.dll!Azure.Identity.EnvironmentCredential.GetTokenAsync(Azure.Core.TokenRequestContext requestContext, System.Threading.CancellationToken cancellationToken) Line 79
    at Azure.Identity\EnvironmentCredential.cs(79)
Azure.Identity.dll!Azure.Identity.DefaultAzureCredential.GetTokenFromSourcesAsync(Azure.Core.TokenCredential[] sources, Azure.Core.TokenRequestContext requestContext, bool async, System.Threading.CancellationToken cancellationToken) Line 107
    at Azure.Identity\DefaultAzureCredential.cs(107)
Azure.Identity.dll!Azure.Identity.DefaultAzureCredential.GetTokenImplAsync(bool async, Azure.Core.TokenRequestContext requestContext, System.Threading.CancellationToken cancellationToken) Line 73
    at Azure.Identity\DefaultAzureCredential.cs(73)
Azure.Identity.dll!Azure.Identity.DefaultAzureCredential.GetTokenAsync(Azure.Core.TokenRequestContext requestContext, System.Threading.CancellationToken cancellationToken) Line 56
    at Azure.Identity\DefaultAzureCredential.cs(56)
Microsoft.Data.SqlClient.dll!Microsoft.Data.SqlClient.ActiveDirectoryAuthenticationProvider.AcquireTokenAsync(Microsoft.Data.SqlClient.SqlAuthenticationParameters parameters)
Microsoft.Data.SqlClient.dll!Microsoft.Data.SqlClient.SqlInternalConnectionTds.GetFedAuthToken.AnonymousMethod__1()
System.Private.CoreLib.dll!System.Threading.Tasks.Task<System.Threading.Tasks.Task<Microsoft.Data.SqlClient.SqlAuthenticationToken>>.InnerInvoke()
System.Private.CoreLib.dll!System.Threading.ExecutionContext.RunFromThreadPoolDispatchLoop(System.Threading.Thread threadPoolThread, System.Threading.ExecutionContext executionContext, System.Threading.ContextCallback callback, object state)
System.Private.CoreLib.dll!System.Threading.Tasks.Task.ExecuteWithThreadLocal(ref System.Threading.Tasks.Task currentTaskSlot, System.Threading.Thread threadPoolThread)
System.Private.CoreLib.dll!System.Threading.ThreadPoolWorkQueue.Dispatch()
System.Private.CoreLib.dll!System.Threading.PortableThreadPool.WorkerThread.WorkerThreadStart()

I have studied the help mentioned here and conclude my code is trying to authenticate a service principal using the JWT token set up in the middle tier.

The middle tier code has been copied from the working application to the problem application with adjustments to work with the different module project.

Thus the azure keys are the same.

I arent sure how to proceed troubleshooting this, other than perhaps to copy code gradually from the bad application into the good to see where it breaks.

Update Studying the Middle Tier Security documentation I see that the Middle Tier Security serveracts as a WebSocket service between the client application and the database server. I think I must be wrong about a service principal being involved. All the middle tier is doing is protecting the connection string.

I want to upgrade my XAF 24.1.6 Winforms application to use middletier security and connect to a database in Azure.

I managed to get "Hello Middle Tier" working with the database. However the full application has many more features.

I copied the working Middle Tier to my full application but when I run it I get the following

I see the middle tier url has not quite loaded when I get the error, causing me to wonder if it is a timing issue.

The call stack is

System.Private.CoreLib.dll!System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
Azure.Identity.dll!Azure.Identity.CredentialDiagnosticScope.FailWrapAndThrow(System.Exception ex, string additionalMessage, bool isCredentialUnavailable) Line 45
    at Azure.Identity\CredentialDiagnosticScope.cs(45)
Azure.Identity.dll!Azure.Identity.EnvironmentCredential.GetTokenImplAsync(bool async, Azure.Core.TokenRequestContext requestContext, System.Threading.CancellationToken cancellationToken) Line 87
    at Azure.Identity\EnvironmentCredential.cs(87)
Azure.Identity.dll!Azure.Identity.EnvironmentCredential.GetTokenAsync(Azure.Core.TokenRequestContext requestContext, System.Threading.CancellationToken cancellationToken) Line 79
    at Azure.Identity\EnvironmentCredential.cs(79)
Azure.Identity.dll!Azure.Identity.DefaultAzureCredential.GetTokenFromSourcesAsync(Azure.Core.TokenCredential[] sources, Azure.Core.TokenRequestContext requestContext, bool async, System.Threading.CancellationToken cancellationToken) Line 107
    at Azure.Identity\DefaultAzureCredential.cs(107)
Azure.Identity.dll!Azure.Identity.DefaultAzureCredential.GetTokenImplAsync(bool async, Azure.Core.TokenRequestContext requestContext, System.Threading.CancellationToken cancellationToken) Line 73
    at Azure.Identity\DefaultAzureCredential.cs(73)
Azure.Identity.dll!Azure.Identity.DefaultAzureCredential.GetTokenAsync(Azure.Core.TokenRequestContext requestContext, System.Threading.CancellationToken cancellationToken) Line 56
    at Azure.Identity\DefaultAzureCredential.cs(56)
Microsoft.Data.SqlClient.dll!Microsoft.Data.SqlClient.ActiveDirectoryAuthenticationProvider.AcquireTokenAsync(Microsoft.Data.SqlClient.SqlAuthenticationParameters parameters)
Microsoft.Data.SqlClient.dll!Microsoft.Data.SqlClient.SqlInternalConnectionTds.GetFedAuthToken.AnonymousMethod__1()
System.Private.CoreLib.dll!System.Threading.Tasks.Task<System.Threading.Tasks.Task<Microsoft.Data.SqlClient.SqlAuthenticationToken>>.InnerInvoke()
System.Private.CoreLib.dll!System.Threading.ExecutionContext.RunFromThreadPoolDispatchLoop(System.Threading.Thread threadPoolThread, System.Threading.ExecutionContext executionContext, System.Threading.ContextCallback callback, object state)
System.Private.CoreLib.dll!System.Threading.Tasks.Task.ExecuteWithThreadLocal(ref System.Threading.Tasks.Task currentTaskSlot, System.Threading.Thread threadPoolThread)
System.Private.CoreLib.dll!System.Threading.ThreadPoolWorkQueue.Dispatch()
System.Private.CoreLib.dll!System.Threading.PortableThreadPool.WorkerThread.WorkerThreadStart()

I have studied the help mentioned here and conclude my code is trying to authenticate a service principal using the JWT token set up in the middle tier.

The middle tier code has been copied from the working application to the problem application with adjustments to work with the different module project.

Thus the azure keys are the same.

I arent sure how to proceed troubleshooting this, other than perhaps to copy code gradually from the bad application into the good to see where it breaks.

Update Studying the Middle Tier Security documentation I see that the Middle Tier Security serveracts as a WebSocket service between the client application and the database server. I think I must be wrong about a service principal being involved. All the middle tier is doing is protecting the connection string.

Share Improve this question edited Nov 19, 2024 at 21:58 Kirsten asked Nov 19, 2024 at 5:00 KirstenKirsten 18.3k50 gold badges209 silver badges361 bronze badges 2
  • 1 Check if this helps stackoverflow/questions/77978952/… – Sridevi Commented Nov 19, 2024 at 14:51
  • Thank you I added azure-sql-database to the tags. From my call stack I see it is something to do with Microsoft.data.SqlClient.ActiveDirectoryAuthentication. Both apps use the same connection string. – Kirsten Commented Nov 19, 2024 at 22:00
Add a comment  | 

1 Answer 1

Reset to default 0

I had fotten to Enable Just My Code. When I did that, the error was clear.

System.InvalidCastException: 'The AddSecuredEFCore method does not work in applications with Middle Tier Security. Use the AddEFCore method instead. In Multi-Tenant applications, ensure that the WithHostDbContext method is called with the isMiddleTier parameter set to true.'

I was able to find the method in the Win project and correct it.

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745581394a4634276.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信