I am using auth0 of my mvc application, and I want to retrieve the email but I find it in claims and its value during execution is null.
here is my code
public async Task Callback()
{
var result = await HttpContext.AuthenticateAsync();
if (result?.Principal != null)
{
// Extraire l’email depuis les claims si disponible
var email = result.Principal.FindFirst(“email”)?.Value;
var sub = result.Principal.FindFirst(“Name”)?.Value;
if (email != null)
{
ViewBag.Email = email; // Optionnel : stockez l'email pour l'utiliser dans la vue
ViewBag.Message = "Connexion réussie avec email !";
}
else
{
ViewBag.Message = "Connexion réussie, mais l'email est introuvable.";
}
return View("Success");
}
ViewBag.Message = "Erreur d'authentification.";
return View("Error");
in action\library I created an action from scratch and I deployed here is my code:
exports.onExecutePostLogin = async (event, api) => {
// Vérifiez si l’utilisateur a un email
if (event.user.email) {
// Ajoutez un claim personnalisé avec l’email dans le token
api.accessToken.setCustomClaim(‘https://localhost:7296//email’, event.user.email);
}
};
Are there any steps left to take to attach it to my application?
// Set claims in ID token
api.idToken.setCustomClaim(`${namespace}/email`, email);
// Set claims in access token
api.accessToken.setCustomClaim(`${namespace}/email`, email);