Skip to content

UUF: Fix AuthMessageSenderOptions reg in auth tutorial #36037

@wadepickett

Description

@wadepickett

Description

Problem
Users following the "Account confirmation and password recovery in ASP.NET Core" tutorial are experiencing an error: "<AuthMessageSenderOptions> throws error as undefined" when implementing email functionality.

Root Cause
The current documentation shows this code for registering the options:

builder.Services.Configure<AuthMessageSenderOptions>(builder.Configuration);

This doesn't properly bind to any specific configuration section, causing the AuthMessageSenderOptions class to be undefined when injected into services.

Proposed Solution
Update the "Configure app to support email" section in the tutorial to properly register the AuthMessageSenderOptions class:

// Add EmailSender as a transient service
builder.Services.AddTransient<IEmailSender, EmailSender>();
// Register the AuthMessageSenderOptions configuration instance
builder.Services.Configure<AuthMessageSenderOptions>(options =>
{
    // Bind directly to the user secrets key
    options.SendGridKey = builder.Configuration["SendGridKey"];
});

The key change here is in how the AuthMessageSenderOptions class gets registered.
Instead of using builder.Services.Configure<AuthMessageSenderOptions>(builder.Configuration),
which doesn't properly bind to any specific configuration section, this update explicitly binds
the SendGridKey from the configuration to the options object.

This prevents the "<AuthMessageSenderOptions> throws error as undefined" error that can occur
when the options class isn't properly registered in the dependency injection container.

Page URL

https://learn.microsoft.com/en-us/aspnet/core/security/authentication/accconfirm?view=aspnetcore-9.0&tabs=visual-studio

Content source URL

https://github.com/dotnet/AspNetCore.Docs/blob/main/aspnetcore/security/authentication/accconfirm.md

Document ID

98e7aacb-2a01-d581-9b03-bfef2893163e

Platform Id

8efad4e0-06aa-bbe0-6133-4092aed18e42

Article author

@wadepickett

Metadata

  • ID: fe1bea60-d173-f6d2-3559-b147699e295a
  • PlatformId: 8efad4e0-06aa-bbe0-6133-4092aed18e42
  • Service: aspnet-core
  • Sub-service: security

Related Issues

Metadata

Metadata

Assignees

Labels

Source - Docs.msDocs Customer feedback via GitHub Issueaspnet-core/svcsecurity/subsvcuser-feedbackIssues that are created from user feedback in the Unified User Feedback control.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions