I am using a external authentication (Google y Microsoft) in mvc Project (vb.NET). It is work good when i use only one instance in Azure. But when i use multi instances always fail (return null) but I see than the urls are correct. I use a MachineKey in web.config pero it is not solve nothing. I am using a classic web role.
In development or with a single instance it works. If I put more than one instance it always fails (except if I was authenticated with an instance, in that case the authentication still works)
I only use external cookie, since I only need to determine that they have been authenticated, but not save their identity in a local authentication cookie
Public Sub ConfigureAuth(app As IAppBuilder)
app.UseExternalSignInCookie(DefaultAuthenticationTypes.ExternalCookie)
Dim options = New MicrosoftAccountAuthenticationOptions With {
.ClientId = "CLIENID",
.ClientSecret = "SECRET",
.CallbackPath = New PathString("/signinMS")
}
app.UseMicrosoftAccountAuthentication(
options
)
app.UseGoogleAuthentication(New GoogleOAuth2AuthenticationOptions() With {
.ClientId = "CLIENTID",
.ClientSecret = "SECRET"
})
End Sub
Example function callback (where is the error)
<AllowAnonymous>
Public Async Function ExternalLoginCallback() As Task(Of ActionResult)
Dim loginInfo = Await AuthenticationManager.GetExternalLoginInfoAsync()
If loginInfo Is Nothing Then
Return Redirect("/")
End If
Request.GetOwinContext().Authentication.SignOut(HttpContext.GetOwinContext().Authentication.GetAuthenticationTypes().Select(Function(o)
Return o.AuthenticationType
End Function).ToArray())
Return Redirect("/Areatrabajo")
End Function
PROBLEM FOUND
Found the problem. Increasing Web Role instances in azure changes the machineKey. For this reason, I cannot use the authentication cookies of the other instances.