Język

HttpRequestMessageAuthenticationExtensions.WithAuthenticationOptions Metoda

Definicja

Przeciążenia

Nazwa Opis
WithAuthenticationOptions(HttpRequestMessage, MicrosoftIdentityMessageHandlerOptions)

Ustawia opcje uwierzytelniania dla żądania HTTP.

WithAuthenticationOptions(HttpRequestMessage, Action<MicrosoftIdentityMessageHandlerOptions>)

Konfiguruje opcje uwierzytelniania dla żądania HTTP przy użyciu delegata.

WithAuthenticationOptions(HttpRequestMessage, MicrosoftIdentityMessageHandlerOptions)

Ustawia opcje uwierzytelniania dla żądania HTTP.

public static System.Net.Http.HttpRequestMessage WithAuthenticationOptions(this System.Net.Http.HttpRequestMessage request, Microsoft.Identity.Web.MicrosoftIdentityMessageHandlerOptions options);
static member WithAuthenticationOptions : System.Net.Http.HttpRequestMessage * Microsoft.Identity.Web.MicrosoftIdentityMessageHandlerOptions -> System.Net.Http.HttpRequestMessage
<Extension()>
Public Function WithAuthenticationOptions (request As HttpRequestMessage, options As MicrosoftIdentityMessageHandlerOptions) As HttpRequestMessage

Parametry

request
HttpRequestMessage

Komunikat żądania HTTP do skonfigurowania.

options
MicrosoftIdentityMessageHandlerOptions

Opcje uwierzytelniania, które mają być stosowane do tego żądania.

Zwraca

Ten sam komunikat żądania dla tworzenia łańcucha metod.

Wyjątki

Zgłaszany, gdy request element lub options ma wartość null.

Przykłady

var options = new MicrosoftIdentityMessageHandlerOptions
{
    Scopes = { "https://graph.microsoft.com/.default" }
};
options.WithAgentIdentity("my-agent-guid");

var request = new HttpRequestMessage(HttpMethod.Get, "/me")
    .WithAuthenticationOptions(options);

Uwagi

Ta metoda zastąpi wszystkie istniejące opcje uwierzytelniania ustawione na żądanie. Obiekt options można dodatkowo skonfigurować za pomocą metod rozszerzeń z innych pakietów sieci Web Microsoft Identity.

Dotyczy

WithAuthenticationOptions(HttpRequestMessage, Action<MicrosoftIdentityMessageHandlerOptions>)

Konfiguruje opcje uwierzytelniania dla żądania HTTP przy użyciu delegata.

public static System.Net.Http.HttpRequestMessage WithAuthenticationOptions(this System.Net.Http.HttpRequestMessage request, Action<Microsoft.Identity.Web.MicrosoftIdentityMessageHandlerOptions> configure);
static member WithAuthenticationOptions : System.Net.Http.HttpRequestMessage * Action<Microsoft.Identity.Web.MicrosoftIdentityMessageHandlerOptions> -> System.Net.Http.HttpRequestMessage
<Extension()>
Public Function WithAuthenticationOptions (request As HttpRequestMessage, configure As Action(Of MicrosoftIdentityMessageHandlerOptions)) As HttpRequestMessage

Parametry

request
HttpRequestMessage

Komunikat żądania HTTP do skonfigurowania.

configure
Action<MicrosoftIdentityMessageHandlerOptions>

Delegat, który konfiguruje opcje uwierzytelniania.

Zwraca

Ten sam komunikat żądania dla tworzenia łańcucha metod.

Wyjątki

Zgłaszany, gdy request element lub configure ma wartość null.

Przykłady

var request = new HttpRequestMessage(HttpMethod.Get, "/api/users")
    .WithAuthenticationOptions(options =>
    {
        options.Scopes.Add("https://myapi.domain.com/user.read");
        options.WithAgentIdentity("agent-application-id");
        options.RequestAppToken = true;
    });

Uwagi

Jeśli żądanie ma już skonfigurowane opcje uwierzytelniania, delegat otrzyma istniejący obiekt opcji do zmodyfikowania. W przeciwnym razie zostanie utworzone nowe MicrosoftIdentityMessageHandlerOptions wystąpienie i przekazane do delegata.

Ta metoda jest szczególnie przydatna, gdy należy zastosować metody rozszerzenia z innych pakietów sieci Web Microsoft Identity, takich jak metody tożsamości agenta.

Dotyczy