IDownstreamWebApi.CallWebApiForUserAsync Method

Definition

Overloads

CallWebApiForUserAsync(String, Action<DownstreamWebApiOptions>, ClaimsPrincipal, StringContent)

Calls the downstream web API for the user, based on a description of the downstream web API in the configuration.

CallWebApiForUserAsync(String, String, Action<DownstreamWebApiOptions>, ClaimsPrincipal, StringContent)

Calls the downstream web API for the user, based on a description of the downstream web API in the configuration.

CallWebApiForUserAsync<TInput,TOutput>(String, TInput, Action<DownstreamWebApiOptions>, ClaimsPrincipal)

Calls a downstream web API consuming JSON with some data and returns data.

CallWebApiForUserAsync<TInput,TOutput>(String, TInput, String, Action<DownstreamWebApiOptions>, ClaimsPrincipal)

Calls a downstream web API consuming JSON with some data and returns data.

CallWebApiForUserAsync(String, Action<DownstreamWebApiOptions>, ClaimsPrincipal, StringContent)

Calls the downstream web API for the user, based on a description of the downstream web API in the configuration.

public virtual System.Threading.Tasks.Task<System.Net.Http.HttpResponseMessage> CallWebApiForUserAsync (string serviceName, Action<Microsoft.Identity.Web.DownstreamWebApiOptions>? calledDownstreamWebApiOptionsOverride = default, System.Security.Claims.ClaimsPrincipal? user = default, System.Net.Http.StringContent? content = default);
abstract member CallWebApiForUserAsync : string * Action<Microsoft.Identity.Web.DownstreamWebApiOptions> * System.Security.Claims.ClaimsPrincipal * System.Net.Http.StringContent -> System.Threading.Tasks.Task<System.Net.Http.HttpResponseMessage>
override this.CallWebApiForUserAsync : string * Action<Microsoft.Identity.Web.DownstreamWebApiOptions> * System.Security.Claims.ClaimsPrincipal * System.Net.Http.StringContent -> System.Threading.Tasks.Task<System.Net.Http.HttpResponseMessage>
Public Overridable Function CallWebApiForUserAsync (serviceName As String, Optional calledDownstreamWebApiOptionsOverride As Action(Of DownstreamWebApiOptions) = Nothing, Optional user As ClaimsPrincipal = Nothing, Optional content As StringContent = Nothing) As Task(Of HttpResponseMessage)

Parameters

serviceName
String

Name of the service describing the downstream web API. There can be several configuration named sections mapped to a DownstreamWebApiOptions, each for one downstream web API. You can pass-in null, but in that case calledDownstreamWebApiOptionsOverride needs to be set.

calledDownstreamWebApiOptionsOverride
Action<DownstreamWebApiOptions>

Overrides the options proposed in the configuration described by serviceName.

user
ClaimsPrincipal

[Optional] Claims representing a user. This is useful on platforms like Blazor or Azure Signal R, where the HttpContext is not available. In other platforms, the library will find the user from the HttpContext.

content
StringContent

HTTP context in the case where HttpMethod is Patch, Post, Put.

Returns

An HttpResponseMessage that the application will process.

Applies to

CallWebApiForUserAsync(String, String, Action<DownstreamWebApiOptions>, ClaimsPrincipal, StringContent)

Calls the downstream web API for the user, based on a description of the downstream web API in the configuration.

public System.Threading.Tasks.Task<System.Net.Http.HttpResponseMessage> CallWebApiForUserAsync (string serviceName, string? authenticationScheme, Action<Microsoft.Identity.Web.DownstreamWebApiOptions>? calledDownstreamWebApiOptionsOverride = default, System.Security.Claims.ClaimsPrincipal? user = default, System.Net.Http.StringContent? content = default);
abstract member CallWebApiForUserAsync : string * string * Action<Microsoft.Identity.Web.DownstreamWebApiOptions> * System.Security.Claims.ClaimsPrincipal * System.Net.Http.StringContent -> System.Threading.Tasks.Task<System.Net.Http.HttpResponseMessage>
Public Function CallWebApiForUserAsync (serviceName As String, authenticationScheme As String, Optional calledDownstreamWebApiOptionsOverride As Action(Of DownstreamWebApiOptions) = Nothing, Optional user As ClaimsPrincipal = Nothing, Optional content As StringContent = Nothing) As Task(Of HttpResponseMessage)

Parameters

serviceName
String

Name of the service describing the downstream web API. There can be several configuration named sections mapped to a DownstreamWebApiOptions, each for one downstream web API. You can pass-in null, but in that case calledDownstreamWebApiOptionsOverride needs to be set.

authenticationScheme
String

Authentication scheme. If null, will use OpenIdConnectDefault.AuthenticationScheme if called from a web app, and JwtBearerDefault.AuthenticationScheme if called from a web API.

calledDownstreamWebApiOptionsOverride
Action<DownstreamWebApiOptions>

Overrides the options proposed in the configuration described by serviceName.

user
ClaimsPrincipal

[Optional] Claims representing a user. This is useful on platforms like Blazor or Azure Signal R, where the HttpContext is not available. In other platforms, the library will find the user from the HttpContext.

content
StringContent

HTTP context in the case where HttpMethod is Patch, Post, Put.

Returns

An HttpResponseMessage that the application will process.

Applies to

CallWebApiForUserAsync<TInput,TOutput>(String, TInput, Action<DownstreamWebApiOptions>, ClaimsPrincipal)

Calls a downstream web API consuming JSON with some data and returns data.

public virtual System.Threading.Tasks.Task<TOutput?> CallWebApiForUserAsync<TInput,TOutput> (string serviceName, TInput input, Action<Microsoft.Identity.Web.DownstreamWebApiOptions>? downstreamWebApiOptionsOverride = default, System.Security.Claims.ClaimsPrincipal? user = default) where TOutput : class;
abstract member CallWebApiForUserAsync : string * 'Input * Action<Microsoft.Identity.Web.DownstreamWebApiOptions> * System.Security.Claims.ClaimsPrincipal -> System.Threading.Tasks.Task<'Output (requires 'Output : null)> (requires 'Output : null)
override this.CallWebApiForUserAsync : string * 'Input * Action<Microsoft.Identity.Web.DownstreamWebApiOptions> * System.Security.Claims.ClaimsPrincipal -> System.Threading.Tasks.Task<'Output (requires 'Output : null)> (requires 'Output : null)
Public Overridable Function CallWebApiForUserAsync(Of TInput, TOutput) (serviceName As String, input As TInput, Optional downstreamWebApiOptionsOverride As Action(Of DownstreamWebApiOptions) = Nothing, Optional user As ClaimsPrincipal = Nothing) As Task(Of TOutput)

Type Parameters

TInput

Input type.

TOutput

Output type.

Parameters

serviceName
String

Name of the service describing the downstream web API. There can be several configuration named sections mapped to a DownstreamWebApiOptions, each for one downstream web API. You can pass-in null, but in that case downstreamWebApiOptionsOverride needs to be set.

input
TInput

Input parameter to the downstream web API.

downstreamWebApiOptionsOverride
Action<DownstreamWebApiOptions>

Overrides the options proposed in the configuration described by serviceName.

user
ClaimsPrincipal

[Optional] Claims representing a user. This is useful in platforms like Blazor or Azure Signal R, where the HttpContext is not available. In other platforms, the library will find the user from the HttpContext.

Returns

Task<TOutput>

The value returned by the downstream web API.

Examples

A list method that returns an IEnumerable<MyItem>>.

public Task<IEnumerable<MyItem>> GetAsync()
{
 return _downstreamWebApi.CallWebApiForUserAsync<object, IEnumerable<MyItem>>(
        ServiceName,
        null,
        options =>
        {
          options.RelativePath = $"api/todolist";
        });
}

Example of editing.

public Task<MyItem> EditAsync(MyItem myItem)
{
  return _downstreamWebApi.CallWebApiForUserAsync<MyItem, MyItem>(
        ServiceName,
        nyItem,
        options =>
        {
           options.HttpMethod = HttpMethod.Patch;
           options.RelativePath = $"api/todolist/{myItem.Id}";
        });
}

Applies to

CallWebApiForUserAsync<TInput,TOutput>(String, TInput, String, Action<DownstreamWebApiOptions>, ClaimsPrincipal)

Calls a downstream web API consuming JSON with some data and returns data.

public System.Threading.Tasks.Task<TOutput?> CallWebApiForUserAsync<TInput,TOutput> (string serviceName, TInput input, string? authenticationScheme, Action<Microsoft.Identity.Web.DownstreamWebApiOptions>? downstreamWebApiOptionsOverride = default, System.Security.Claims.ClaimsPrincipal? user = default) where TOutput : class;
abstract member CallWebApiForUserAsync : string * 'Input * string * Action<Microsoft.Identity.Web.DownstreamWebApiOptions> * System.Security.Claims.ClaimsPrincipal -> System.Threading.Tasks.Task<'Output (requires 'Output : null)> (requires 'Output : null)
Public Function CallWebApiForUserAsync(Of TInput, TOutput) (serviceName As String, input As TInput, authenticationScheme As String, Optional downstreamWebApiOptionsOverride As Action(Of DownstreamWebApiOptions) = Nothing, Optional user As ClaimsPrincipal = Nothing) As Task(Of TOutput)

Type Parameters

TInput

Input type.

TOutput

Output type.

Parameters

serviceName
String

Name of the service describing the downstream web API. There can be several configuration named sections mapped to a DownstreamWebApiOptions, each for one downstream web API. You can pass-in null, but in that case downstreamWebApiOptionsOverride needs to be set.

input
TInput

Input parameter to the downstream web API.

authenticationScheme
String

Authentication scheme. If null, will use OpenIdConnectDefault.AuthenticationScheme if called from a web app, and JwtBearerDefault.AuthenticationScheme if called from a web API.

downstreamWebApiOptionsOverride
Action<DownstreamWebApiOptions>

Overrides the options proposed in the configuration described by serviceName.

user
ClaimsPrincipal

[Optional] Claims representing a user. This is useful in platforms like Blazor or Azure Signal R, where the HttpContext is not available. In other platforms, the library will find the user from the HttpContext.

Returns

Task<TOutput>

The value returned by the downstream web API.

Examples

A list method that returns an IEnumerable<MyItem>>.

public Task<IEnumerable<MyItem>> GetAsync()
{
 return _downstreamWebApi.CallWebApiForUserAsync<object, IEnumerable<MyItem>>(
        ServiceName,
        null,
        options =>
        {
          options.RelativePath = $"api/todolist";
        });
}

Example of editing.

public Task<MyItem> EditAsync(MyItem myItem)
{
  return _downstreamWebApi.CallWebApiForUserAsync<MyItem, MyItem>(
        ServiceName,
        nyItem,
        options =>
        {
           options.HttpMethod = HttpMethod.Patch;
           options.RelativePath = $"api/todolist/{myItem.Id}";
        });
}

Applies to