-
Notifications
You must be signed in to change notification settings - Fork 210
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
update Id web to support authentication handlers other than JwtBearer… (
#1498) * update Id web to support authentication handlers other than JwtBearer and provide extension method * make class static * PR feedback from george
- Loading branch information
Showing
5 changed files
with
120 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
50 changes: 50 additions & 0 deletions
50
src/Microsoft.Identity.Web/WebApiExtensions/WebApiBuilders.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
// Copyright (c) Microsoft Corporation. All rights reserved. | ||
// Licensed under the MIT License. | ||
|
||
using System; | ||
using Microsoft.Extensions.Configuration; | ||
using Microsoft.Extensions.DependencyInjection; | ||
using Microsoft.Extensions.Options; | ||
using Microsoft.Identity.Client; | ||
|
||
namespace Microsoft.Identity.Web.Internal | ||
{ | ||
/// <summary> | ||
/// Web API authentication builder. | ||
/// </summary> | ||
public static class WebApiBuilders | ||
{ | ||
/// <summary> | ||
/// Allows a higher level abstraction of security token (i.e. System.IdentityModel.Tokens.Jwt and more modern, Microsoft.IdentityModel.JsonWebTokens) | ||
/// to be used with Microsoft Identity Web. | ||
/// Developers should continue to use `EnableTokenAcquisitionToCallDownstreamApi`. | ||
/// This API is not considered part of the public API and may change. | ||
/// </summary> | ||
/// <param name="configureConfidentialClientApplicationOptions">The action to configure <see cref="ConfidentialClientApplicationOptions"/>.</param> | ||
/// <param name="authenticationScheme">Authentication scheme.</param> | ||
/// <param name="services">The services being configured.</param> | ||
/// <param name="configuration">Configuration.</param> | ||
/// <returns>The authentication builder to chain.</returns> | ||
public static MicrosoftIdentityAppCallsWebApiAuthenticationBuilder EnableTokenAcquisition( | ||
Action<ConfidentialClientApplicationOptions> configureConfidentialClientApplicationOptions, | ||
string authenticationScheme, | ||
IServiceCollection services, | ||
IConfiguration? configuration) | ||
{ | ||
services.AddOptions<ConfidentialClientApplicationOptions>(authenticationScheme) | ||
.Configure<IOptionsMonitor<MergedOptions>>(( | ||
ccaOptions, mergedOptionsMonitor) => | ||
{ | ||
configureConfidentialClientApplicationOptions(ccaOptions); | ||
MergedOptions mergedOptions = mergedOptionsMonitor.Get(authenticationScheme); | ||
MergedOptions.UpdateMergedOptionsFromConfidentialClientApplicationOptions(ccaOptions, mergedOptions); | ||
}); | ||
|
||
services.AddTokenAcquisition(); | ||
|
||
return new MicrosoftIdentityAppCallsWebApiAuthenticationBuilder( | ||
services, | ||
configuration as IConfigurationSection); | ||
} | ||
} | ||
} |