TokenAcquirerFactory.GetDefaultInstance Method
Definition
Important
Some information relates to prerelease product that may be substantially modified before it’s released. Microsoft makes no warranties, express or implied, with respect to the information provided here.
Overloads
GetDefaultInstance(String) |
Get the default instance. Use this method to retrieve the instance, optionally add some services to the service collection, and build the instance. |
GetDefaultInstance<T>(String) |
Get the default instance of a token acquirer factory. Use this method, for instance, if you have an ASP.NET OWIN application and you want to get the default instance of the OwinTokenAcquirerFactory. |
GetDefaultInstance(String)
Get the default instance. Use this method to retrieve the instance, optionally add some services to the service collection, and build the instance.
public static Microsoft.Identity.Web.TokenAcquirerFactory GetDefaultInstance (string configSection = "AzureAd");
static member GetDefaultInstance : string -> Microsoft.Identity.Web.TokenAcquirerFactory
Public Shared Function GetDefaultInstance (Optional configSection As String = "AzureAd") As TokenAcquirerFactory
Parameters
- configSection
- String
Returns
Examples
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Graph;
using Microsoft.Identity.Web;
var tokenAcquirerFactory = TokenAcquirerFactory.GetDefaultInstance();
tokenAcquirerFactory.Services.AddMicrosoftGraph();
var sp = tokenAcquirerFactory.Build();
var graphServiceClient = sp.GetRequiredService<GraphServiceClient>();
var users = await graphServiceClient.Users
.Request()
.WithAppOnly()
.GetAsync();
Console.WriteLine($"{users.Count} users");
Applies to
GetDefaultInstance<T>(String)
Get the default instance of a token acquirer factory. Use this method, for instance, if you have an ASP.NET OWIN application and you want to get the default instance of the OwinTokenAcquirerFactory.
public static T GetDefaultInstance<T> (string configSection = "AzureAd") where T : Microsoft.Identity.Web.TokenAcquirerFactory, new();
static member GetDefaultInstance : string -> 'T (requires 'T :> Microsoft.Identity.Web.TokenAcquirerFactory and 'T : (new : unit -> 'T))
Public Shared Function GetDefaultInstance(Of T As {TokenAcquirerFactoryNew}) (Optional configSection As String = "AzureAd") As T
Type Parameters
- T
Parameters
- configSection
- String
Returns
Examples
using Microsoft.Owin.Security;
using Microsoft.Owin.Security.Cookies;
using Owin;
using Microsoft.Identity.Web;
using Microsoft.Identity.Web.TokenCacheProviders.InMemory;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Identity.Client;
using Microsoft.Identity.Web.OWIN;
namespace OwinWebApp
{
public partial class Startup
{
public void ConfigureAuth(IAppBuilder app)
{
app.SetDefaultSignInAsAuthenticationType(CookieAuthenticationDefaults.AuthenticationType);
app.UseCookieAuthentication(new CookieAuthenticationOptions());
OwinTokenAcquirerFactory factory = TokenAcquirerFactory.GetDefaultInstance<OwinTokenAcquirerFactory>();
app.AddMicrosoftIdentityWebApp(factory);
factory.Services
.Configure<ConfidentialClientApplicationOptions>(options => { options.RedirectUri = "https://localhost:44386/"; })
.AddMicrosoftGraph()
.AddDownstreamApi("DownstreamAPI1", factory.Configuration.GetSection("DownstreamAPI"))
.AddInMemoryTokenCaches();
factory.Build();
/*
app.AddMicrosoftIdentityWebApp(configureServices: services =>
{
services
.Configure<ConfidentialClientApplicationOptions>(options => { options.RedirectUri = "https://localhost:44386/"; })
.AddMicrosoftGraph()
// WE cannot do that today: Configuration is not available.
// .AddDownstreamApi("CalledApi", null)
.AddInMemoryTokenCaches();
});
*/
}
}
}
Applies to
피드백
https://aka.ms/ContentUserFeedback
출시 예정: 2024년 내내 콘텐츠에 대한 피드백 메커니즘으로 GitHub 문제를 단계적으로 폐지하고 이를 새로운 피드백 시스템으로 바꿀 예정입니다. 자세한 내용은 다음을 참조하세요.다음에 대한 사용자 의견 제출 및 보기