Authentifizierung gibt Nullinformationen zurück? Aktualisieren der ASP.NET -Core 3.1 -App auf neueste .NET mit MicrosoftC#

Ein Treffpunkt für C#-Programmierer
Anonymous
 Authentifizierung gibt Nullinformationen zurück? Aktualisieren der ASP.NET -Core 3.1 -App auf neueste .NET mit Microsoft

Post by Anonymous »

Ich habe eine aktuelle ASP.NET -Core 3.1 -App, auf die ich (schließlich) upgrade (schließlich) .NET 9. Im Moment ziele ich auf .NET 6, da es die letzte Version, in der die von mir verwendeten Pakete nicht veraltet wurden. Dies funktioniert seit Jahren gut, verwendet jedoch die Microsoft.aspnetcore.Authentication.azuread.ui Pakete, die jetzt veraltet sind. Ich versuche, Microsoft.Identity.Web stattdessen zu verwenden. Ich sehe die Authentifizierungsdaten jedoch nicht im Rückruf.

Code: Select all

Startup.cs
:

Code: Select all

services.AddAuthentication(defaultScheme: AzureADDefaults.AuthenticationScheme).AddAzureAD(options => Configuration.Bind("AzureAd", options));

services.Configure (AzureADDefaults.OpenIdScheme, options =>
{
options.Events = new OpenIdConnectEvents
{
OnRedirectToIdentityProvider = async context =>
{
if (context.Properties.Items.TryGetValue("userId", out var userId))
{
context.ProtocolMessage.LoginHint = userId;
}

await Task.Yield();
},
};
});
< /code>
Login: < /p>
var redirectUrl = Url.Page("/Account/ExternalLogin", pageHandler: "Callback", values: new { returnUrl, area = "Identity" });
var properties = _signInManager.ConfigureExternalAuthenticationProperties(AzureADDefaults.AuthenticationScheme, redirectUrl);
properties.Items["userId"] = Input.Email;

return new ChallengeResult(AzureADDefaults.AuthenticationScheme, properties);
< /code>
Rückruf: < /p>
public async Task OnGetCallbackAsync(string returnUrl = null, string remoteError = null)
{
returnUrl = returnUrl ?? Url.Content("~/");

var info = await _signInManager.GetExternalLoginInfoAsync();
}
< /code>
Das habe ich geändert in: < /p>
Startup.cs
:

Code: Select all

services.AddAuthentication().AddMicrosoftIdentityWebApp(options =>
{
Configuration.Bind("AzureAd", options);
options.Events ??= new OpenIdConnectEvents();
options.GetClaimsFromUserInfoEndpoint = true;

options.Events = new OpenIdConnectEvents
{
OnRedirectToIdentityProvider = async context =>
{
if (context.Properties.Items.TryGetValue("userId", out var userId))
{
context.ProtocolMessage.LoginHint = userId;
}

await Task.Yield();
},
};
});
< /code>
Login: < /p>
 var redirectUrl = Url.Page("/Account/ExternalLogin", pageHandler: "Callback", values: new { returnUrl, area = "Identity" });
var properties = _signInManager.ConfigureExternalAuthenticationProperties(OpenIdConnectDefaults.AuthenticationScheme, redirectUrl);
properties.Items["userId"] = Input.Email;

return new ChallengeResult(OpenIdConnectDefaults.AuthenticationScheme, properties);
< /code>
Rückruf bleibt gleich. Es fühlt sich an, als wäre ich nah, aber vielleicht unterscheidet sich die Rückgabedaten irgendwie zwischen der Verwendung von Azuread OpenID (AzureADDefaults.OpenIdScheme
) gegen openID connect (

Code: Select all

OpenIdConnectDefaults.AuthenticationScheme
)? Ich vermute, ich setze entweder nicht das richtige Authentifizierungsschema selbst fest oder es gibt eine Option, die ich für die Authentifizierungsdaten für die richtige Übersetzung muss.

Code: Select all

services.AddAuthentication(OpenIdConnectDefaults.AuthenticationScheme)
.AddMicrosoftIdentityWebApp(Configuration);
immer noch das gleiche Verhalten.

Quick Reply

Change Text Case: 
   
  • Similar Topics
    Replies
    Views
    Last post