I have an ASP.Net Web Forms application in which I have been tasked with implementing Azure AD authentication.
It seems as if, while debugging the application in localhost, the prompt opens properly - it doesn't do any redirection, but I guess that's an issue with my code or Azure settings.
When I deploy the application on its production server on a third party host (not Azure), the authentication prompt will not open at all.
What could the cause of this be?
Below is the code I use for the authentication process
Imports Microsoft.Identity.Client
Imports Microsoft.VisualBasic
Public Class AuthenticationManager
Private Shared app As PublicClientApplication
Shared Sub New()
Dim clientId As String = ConfigurationManager.AppSettings("ida:ClientId")
Dim redirectUri As String = ConfigurationManager.AppSettings("ida:RedirectUri")
Dim tenantId As String = ConfigurationManager.AppSettings("ida:Tenant")
Dim authorityUri = "https://login.microsoftonline.com/" & tenantId
Dim scopes As String() = New String() {"https://graph.microsoft.com/User.Read"}
app = PublicClientApplicationBuilder.Create(clientId).WithAuthority(authorityUri).WithTenantId(tenantId).WithRedirectUri(redirectUri).Build()
End Sub
Public Function GetAuthenticationResult() As String
Try
Dim scopes As String() = New String() {"https://graph.microsoft.com/User.Read"}
Dim result As Microsoft.Identity.Client.AuthenticationResult = app.AcquireTokenInteractive(scopes).WithPrompt(Prompt.ForceLogin).ExecuteAsync().Result
Return result.Account.Username
Catch ex As Exception
Err.Clear()
Return "-"
Exit Function
End Try
End Function
End Class
Private Sub BtnConnectWithAzure_Click(sender As Object, e As EventArgs) Handles BtnConnectWithAzure.Click
Dim t As New Threading.Thread(AddressOf AuthenticateUser)
t.SetApartmentState(ApartmentState.STA)
t.Start()
End Sub
Private Sub AuthenticateUser()
System.Net.ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls11 Or SecurityProtocolType.Tls12
Dim app As New AuthenticationManager
Dim username As String = app.GetAuthenticationResult()
If username <> "-" Then
Response.Redirect(username)
End If
End Sub
What I have tried:
I initially thought this was an issue regarding blocked popups on the browser, but it doesn't seem to be related to that - it doesn't seem to be a permission issue in general. I haven't really found any other suggestions online on what could be causing the issue