Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support overrides of token issuer from environment variables #41945

Merged
merged 26 commits into from
Mar 12, 2024
Merged
Show file tree
Hide file tree
Changes from 17 commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
26ad4f9
Support custom token issures
HarmanDhunna Feb 8, 2024
10fc3ba
v2
HarmanDhunna Feb 8, 2024
7651d40
Comments and clean up
HarmanDhunna Feb 13, 2024
f66245c
Clean up
HarmanDhunna Feb 13, 2024
504f0a9
Add token issuer versions to the trigger attribute
HarmanDhunna Feb 13, 2024
43be0d3
api updates
HarmanDhunna Feb 13, 2024
1ae2b25
Added tests and changed variable name to AuthenticationEvents__OIDCMe…
HarmanDhunna Feb 13, 2024
389c782
Reminder changes for var name change
HarmanDhunna Feb 13, 2024
0e95b4a
API Updates
HarmanDhunna Feb 13, 2024
cf8cce9
SpellCheck fix to OidcMetadataUrl
HarmanDhunna Feb 13, 2024
587b156
Updating cspell.json for oidc
HarmanDhunna Feb 14, 2024
58e3f7b
PR Recommendations
HarmanDhunna Feb 14, 2024
5df0b70
Updated tests
HarmanDhunna Feb 21, 2024
5657ef9
Merge branch 'main' of https://github.com/Azure/azure-sdk-for-net int…
HarmanDhunna Feb 21, 2024
a610a18
API Updates
HarmanDhunna Feb 21, 2024
386e001
Missed the file.
HarmanDhunna Feb 21, 2024
16a8875
Modified how token validation validates
HarmanDhunna Feb 22, 2024
d43091a
Changing sign to back to async
HarmanDhunna Feb 26, 2024
44d4d4b
Update API with new Attribute and remove the old one. Will be a break…
HarmanDhunna Feb 26, 2024
0f5da7d
checked in Test files
HarmanDhunna Feb 26, 2024
3a6bd32
Pull request review recommendations
HarmanDhunna Feb 26, 2024
78e8d82
Update ChangeLog
HarmanDhunna Feb 27, 2024
c173327
Added error Logging for invalid tokens.
HarmanDhunna Mar 2, 2024
5e0b207
Minor changes
HarmanDhunna Mar 2, 2024
bbc50f3
Missing a using statment
HarmanDhunna Mar 2, 2024
8dcc036
Switched to using IsUnsafeSupportLoggingEnabled
HarmanDhunna Mar 5, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions eng/Packages.Data.props
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,8 @@
<PackageReference Update="Microsoft.Identity.Client.Broker" Version="4.56.0" />

<!-- TODO: Make sure this package is arch-board approved -->
<PackageReference Update="Microsoft.IdentityModel.Protocols.OpenIdConnect" Version="6.35.0" />
<PackageReference Update="Microsoft.IdentityModel.Tokens" Version="6.35.0" />
<PackageReference Update="System.IdentityModel.Tokens.Jwt" Version="6.35.0" />
</ItemGroup>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ public partial class AuthenticationEventsTriggerAttribute : System.Attribute
{
public AuthenticationEventsTriggerAttribute() { }
public string AudienceAppId { get { throw null; } set { } }
public string AuthorityUrl { get { throw null; } set { } }
public string TenantId { get { throw null; } set { } }
}
public partial class AuthenticationEventWebJobsStartup : Microsoft.Azure.WebJobs.Hosting.IWebJobsStartup
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@
throw new NotSupportedException(AuthenticationEventResource.Ex_Invalid_Inbound);
}

Dictionary<string, string> Claims = await GetClaimsAndValidateRequest(request).ConfigureAwait(false);
Dictionary<string, string> Claims = GetClaimsAndValidateRequest(request);
string payload = await request.Content.ReadAsStringAsync().ConfigureAwait(false);
AuthenticationEventMetadata eventMetadata = GetEventAndValidateSchema(payload);

Expand Down Expand Up @@ -216,19 +216,19 @@
#endregion

#region Validators
private async Task<Dictionary<string, string>> GetClaimsAndValidateRequest(HttpRequestMessage requestMessage)
private Dictionary<string, string> GetClaimsAndValidateRequest(HttpRequestMessage requestMessage)
{
ConfigurationManager configurationManager = new ConfigurationManager(_authEventTriggerAttr);
if (ConfigurationManager.BypassValidation)
if (configurationManager.BypassValidation)
{
return null;
}

TokenValidator validator = ConfigurationManager.EZAuthEnabled && requestMessage.Headers.Matches(ConfigurationManager.HEADER_EZAUTH_ICP, ConfigurationManager.HEADER_EZAUTH_ICP_VERIFY) ?
(TokenValidator)new TokenValidatorEZAuth() :
TokenValidator validator = configurationManager.EZAuthEnabled && requestMessage.Headers.Matches(ConfigurationManager.HEADER_EZAUTH_ICP, ConfigurationManager.HEADER_EZAUTH_ICP_VERIFY) ?
new TokenValidatorEZAuth() :
new TokenValidatorInternal();

(bool valid, Dictionary<string, string> claims) = await validator.GetClaimsAndValidate(requestMessage, configurationManager).ConfigureAwait(false);
(bool valid, Dictionary<string, string> claims) = validator.ValidateAndGetClaims(requestMessage, configurationManager);

Check failure on line 231 in sdk/entra/Microsoft.Azure.WebJobs.Extensions.AuthenticationEvents/src/AuthenticationEventBinding.cs

View check run for this annotation

Azure Pipelines / net - entra - ci (Build Analyze)

sdk/entra/Microsoft.Azure.WebJobs.Extensions.AuthenticationEvents/src/AuthenticationEventBinding.cs#L231

sdk/entra/Microsoft.Azure.WebJobs.Extensions.AuthenticationEvents/src/AuthenticationEventBinding.cs(231,63): Error CS1061: 'Task<(bool Valid, Dictionary<string, string> Claims)>' does not contain a definition for 'Deconstruct' and no accessible extension method 'Deconstruct' accepting a first argument of type 'Task<(bool Valid, Dictionary<string, string> Claims)>' could be found (are you missing a using directive or an assembly reference?)

Check failure on line 231 in sdk/entra/Microsoft.Azure.WebJobs.Extensions.AuthenticationEvents/src/AuthenticationEventBinding.cs

View check run for this annotation

Azure Pipelines / net - entra - ci (Build Analyze)

sdk/entra/Microsoft.Azure.WebJobs.Extensions.AuthenticationEvents/src/AuthenticationEventBinding.cs#L231

sdk/entra/Microsoft.Azure.WebJobs.Extensions.AuthenticationEvents/src/AuthenticationEventBinding.cs(231,63): Error CS1061: 'Task<(bool Valid, Dictionary<string, string> Claims)>' does not contain a definition for 'Deconstruct' and no accessible extension method 'Deconstruct' accepting a first argument of type 'Task<(bool Valid, Dictionary<string, string> Claims)>' could be found (are you missing a using directive or an assembly reference?)

Check failure on line 231 in sdk/entra/Microsoft.Azure.WebJobs.Extensions.AuthenticationEvents/src/AuthenticationEventBinding.cs

View check run for this annotation

Azure Pipelines / net - entra - ci (Build Analyze)

sdk/entra/Microsoft.Azure.WebJobs.Extensions.AuthenticationEvents/src/AuthenticationEventBinding.cs#L231

sdk/entra/Microsoft.Azure.WebJobs.Extensions.AuthenticationEvents/src/AuthenticationEventBinding.cs(231,63): Error CS8129: No suitable 'Deconstruct' instance or extension method was found for type 'Task<(bool Valid, Dictionary<string, string> Claims)>', with 2 out parameters and a void return type.

Check failure on line 231 in sdk/entra/Microsoft.Azure.WebJobs.Extensions.AuthenticationEvents/src/AuthenticationEventBinding.cs

View check run for this annotation

Azure Pipelines / net - entra - ci (Build Analyze)

sdk/entra/Microsoft.Azure.WebJobs.Extensions.AuthenticationEvents/src/AuthenticationEventBinding.cs#L231

sdk/entra/Microsoft.Azure.WebJobs.Extensions.AuthenticationEvents/src/AuthenticationEventBinding.cs(231,63): Error CS8129: No suitable 'Deconstruct' instance or extension method was found for type 'Task<(bool Valid, Dictionary<string, string> Claims)>', with 2 out parameters and a void return type.

Check failure on line 231 in sdk/entra/Microsoft.Azure.WebJobs.Extensions.AuthenticationEvents/src/AuthenticationEventBinding.cs

View check run for this annotation

Azure Pipelines / net - entra - ci (Build Test Ubuntu2004_NET70_ProjectRef_Release)

sdk/entra/Microsoft.Azure.WebJobs.Extensions.AuthenticationEvents/src/AuthenticationEventBinding.cs#L231

sdk/entra/Microsoft.Azure.WebJobs.Extensions.AuthenticationEvents/src/AuthenticationEventBinding.cs(231,63): Error CS1061: 'Task<(bool Valid, Dictionary<string, string> Claims)>' does not contain a definition for 'Deconstruct' and no accessible extension method 'Deconstruct' accepting a first argument of type 'Task<(bool Valid, Dictionary<string, string> Claims)>' could be found (are you missing a using directive or an assembly reference?)

Check failure on line 231 in sdk/entra/Microsoft.Azure.WebJobs.Extensions.AuthenticationEvents/src/AuthenticationEventBinding.cs

View check run for this annotation

Azure Pipelines / net - entra - ci (Build Test Ubuntu2004_NET70_ProjectRef_Release)

sdk/entra/Microsoft.Azure.WebJobs.Extensions.AuthenticationEvents/src/AuthenticationEventBinding.cs#L231

sdk/entra/Microsoft.Azure.WebJobs.Extensions.AuthenticationEvents/src/AuthenticationEventBinding.cs(231,63): Error CS8129: No suitable 'Deconstruct' instance or extension method was found for type 'Task<(bool Valid, Dictionary<string, string> Claims)>', with 2 out parameters and a void return type.

Check failure on line 231 in sdk/entra/Microsoft.Azure.WebJobs.Extensions.AuthenticationEvents/src/AuthenticationEventBinding.cs

View check run for this annotation

Azure Pipelines / net - entra - ci (Build Test Ubuntu2004_NET60_PackageRef_Debug)

sdk/entra/Microsoft.Azure.WebJobs.Extensions.AuthenticationEvents/src/AuthenticationEventBinding.cs#L231

sdk/entra/Microsoft.Azure.WebJobs.Extensions.AuthenticationEvents/src/AuthenticationEventBinding.cs(231,63): Error CS1061: 'Task<(bool Valid, Dictionary<string, string> Claims)>' does not contain a definition for 'Deconstruct' and no accessible extension method 'Deconstruct' accepting a first argument of type 'Task<(bool Valid, Dictionary<string, string> Claims)>' could be found (are you missing a using directive or an assembly reference?)

Check failure on line 231 in sdk/entra/Microsoft.Azure.WebJobs.Extensions.AuthenticationEvents/src/AuthenticationEventBinding.cs

View check run for this annotation

Azure Pipelines / net - entra - ci (Build Test Ubuntu2004_NET60_PackageRef_Debug)

sdk/entra/Microsoft.Azure.WebJobs.Extensions.AuthenticationEvents/src/AuthenticationEventBinding.cs#L231

sdk/entra/Microsoft.Azure.WebJobs.Extensions.AuthenticationEvents/src/AuthenticationEventBinding.cs(231,63): Error CS8129: No suitable 'Deconstruct' instance or extension method was found for type 'Task<(bool Valid, Dictionary<string, string> Claims)>', with 2 out parameters and a void return type.

Check failure on line 231 in sdk/entra/Microsoft.Azure.WebJobs.Extensions.AuthenticationEvents/src/AuthenticationEventBinding.cs

View check run for this annotation

Azure Pipelines / net - entra - ci (Build Test MacOS11_NET70_ProjectRef_Release)

sdk/entra/Microsoft.Azure.WebJobs.Extensions.AuthenticationEvents/src/AuthenticationEventBinding.cs#L231

sdk/entra/Microsoft.Azure.WebJobs.Extensions.AuthenticationEvents/src/AuthenticationEventBinding.cs(231,63): Error CS1061: 'Task<(bool Valid, Dictionary<string, string> Claims)>' does not contain a definition for 'Deconstruct' and no accessible extension method 'Deconstruct' accepting a first argument of type 'Task<(bool Valid, Dictionary<string, string> Claims)>' could be found (are you missing a using directive or an assembly reference?)

Check failure on line 231 in sdk/entra/Microsoft.Azure.WebJobs.Extensions.AuthenticationEvents/src/AuthenticationEventBinding.cs

View check run for this annotation

Azure Pipelines / net - entra - ci (Build Test MacOS11_NET70_ProjectRef_Release)

sdk/entra/Microsoft.Azure.WebJobs.Extensions.AuthenticationEvents/src/AuthenticationEventBinding.cs#L231

sdk/entra/Microsoft.Azure.WebJobs.Extensions.AuthenticationEvents/src/AuthenticationEventBinding.cs(231,63): Error CS8129: No suitable 'Deconstruct' instance or extension method was found for type 'Task<(bool Valid, Dictionary<string, string> Claims)>', with 2 out parameters and a void return type.

Check failure on line 231 in sdk/entra/Microsoft.Azure.WebJobs.Extensions.AuthenticationEvents/src/AuthenticationEventBinding.cs

View check run for this annotation

Azure Pipelines / net - entra - ci (Build Test MacOS11_NET60_PackageRef_Debug)

sdk/entra/Microsoft.Azure.WebJobs.Extensions.AuthenticationEvents/src/AuthenticationEventBinding.cs#L231

sdk/entra/Microsoft.Azure.WebJobs.Extensions.AuthenticationEvents/src/AuthenticationEventBinding.cs(231,63): Error CS1061: 'Task<(bool Valid, Dictionary<string, string> Claims)>' does not contain a definition for 'Deconstruct' and no accessible extension method 'Deconstruct' accepting a first argument of type 'Task<(bool Valid, Dictionary<string, string> Claims)>' could be found (are you missing a using directive or an assembly reference?)

Check failure on line 231 in sdk/entra/Microsoft.Azure.WebJobs.Extensions.AuthenticationEvents/src/AuthenticationEventBinding.cs

View check run for this annotation

Azure Pipelines / net - entra - ci (Build Test MacOS11_NET60_PackageRef_Debug)

sdk/entra/Microsoft.Azure.WebJobs.Extensions.AuthenticationEvents/src/AuthenticationEventBinding.cs#L231

sdk/entra/Microsoft.Azure.WebJobs.Extensions.AuthenticationEvents/src/AuthenticationEventBinding.cs(231,63): Error CS8129: No suitable 'Deconstruct' instance or extension method was found for type 'Task<(bool Valid, Dictionary<string, string> Claims)>', with 2 out parameters and a void return type.

Check failure on line 231 in sdk/entra/Microsoft.Azure.WebJobs.Extensions.AuthenticationEvents/src/AuthenticationEventBinding.cs

View check run for this annotation

Azure Pipelines / net - entra - ci

sdk/entra/Microsoft.Azure.WebJobs.Extensions.AuthenticationEvents/src/AuthenticationEventBinding.cs#L231

sdk/entra/Microsoft.Azure.WebJobs.Extensions.AuthenticationEvents/src/AuthenticationEventBinding.cs(231,63): Error CS1061: 'Task<(bool Valid, Dictionary<string, string> Claims)>' does not contain a definition for 'Deconstruct' and no accessible extension method 'Deconstruct' accepting a first argument of type 'Task<(bool Valid, Dictionary<string, string> Claims)>' could be found (are you missing a using directive or an assembly reference?)

Check failure on line 231 in sdk/entra/Microsoft.Azure.WebJobs.Extensions.AuthenticationEvents/src/AuthenticationEventBinding.cs

View check run for this annotation

Azure Pipelines / net - entra - ci

sdk/entra/Microsoft.Azure.WebJobs.Extensions.AuthenticationEvents/src/AuthenticationEventBinding.cs#L231

sdk/entra/Microsoft.Azure.WebJobs.Extensions.AuthenticationEvents/src/AuthenticationEventBinding.cs(231,63): Error CS1061: 'Task<(bool Valid, Dictionary<string, string> Claims)>' does not contain a definition for 'Deconstruct' and no accessible extension method 'Deconstruct' accepting a first argument of type 'Task<(bool Valid, Dictionary<string, string> Claims)>' could be found (are you missing a using directive or an assembly reference?)

Check failure on line 231 in sdk/entra/Microsoft.Azure.WebJobs.Extensions.AuthenticationEvents/src/AuthenticationEventBinding.cs

View check run for this annotation

Azure Pipelines / net - entra - ci

sdk/entra/Microsoft.Azure.WebJobs.Extensions.AuthenticationEvents/src/AuthenticationEventBinding.cs#L231

sdk/entra/Microsoft.Azure.WebJobs.Extensions.AuthenticationEvents/src/AuthenticationEventBinding.cs(231,63): Error CS8129: No suitable 'Deconstruct' instance or extension method was found for type 'Task<(bool Valid, Dictionary<string, string> Claims)>', with 2 out parameters and a void return type.

Check failure on line 231 in sdk/entra/Microsoft.Azure.WebJobs.Extensions.AuthenticationEvents/src/AuthenticationEventBinding.cs

View check run for this annotation

Azure Pipelines / net - entra - ci

sdk/entra/Microsoft.Azure.WebJobs.Extensions.AuthenticationEvents/src/AuthenticationEventBinding.cs#L231

sdk/entra/Microsoft.Azure.WebJobs.Extensions.AuthenticationEvents/src/AuthenticationEventBinding.cs(231,63): Error CS8129: No suitable 'Deconstruct' instance or extension method was found for type 'Task<(bool Valid, Dictionary<string, string> Claims)>', with 2 out parameters and a void return type.
if (valid)
{
return claims;
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -204,8 +204,14 @@
<data name="Ex_Token_Version" xml:space="preserve">
<value>Invalid token version {0}, supported versions are: {1}</value>
</data>
<data name="Ex_Trigger_Required_Attrs" xml:space="preserve">
<value>Please supply both the TenantId and AudienceAppId in variables in your binding configuration. (Or app settings {0} and {1})</value>
<data name="Ex_Trigger_ApplicationId_Required" xml:space="preserve">
<value>Please supply the ApplicationId {0} in variables in your binding configuration.</value>
</data>
<data name="Ex_Trigger_AuthorityUrl_Required" xml:space="preserve">
<value>Please supply the Authority URL {0} in variables in your binding configuration.</value>
</data>
<data name="Ex_Trigger_AuthorizedPartyApplicationId_Required" xml:space="preserve">
<value>Please supply the AuthorizedPartyApplicationId {0} in variables in your binding configuration.</value>
</data>
<data name="Log_EventHandler_Url" xml:space="preserve">
<value>Listener registered at: {0}</value>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,19 @@ public AuthenticationEventsTriggerAttribute()
{
}

/// <summary>Gets or sets the tenant identifier.</summary>
/// <value>The tenant identifier.</value>
public string TenantId { get; set; }
/// <summary>Gets or sets the Authorized Party application identifier.</summary>
/// <value>The app id would default to public cloud id</value>
public string AuthorizedPartyAppId { get; set; } = "99045fe1-7639-4a75-9d4a-577b6ca3810f";

/// <summary>Gets or sets the audience application identifier.</summary>
/// <value>The audience application identifier.</value>
public string AudienceAppId { get; set; }

/// <summary>
/// The authority is a URL that indicates the directory where the token came from
/// </summary>
public string AuthorityUrl { get; set; }

internal bool IsParameterString { get; set; } = true;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,77 +2,167 @@
// Licensed under the MIT License.

using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;

using Microsoft.IdentityModel.JsonWebTokens;

namespace Microsoft.Azure.WebJobs.Extensions.AuthenticationEvents
{
/// <summary>
/// Configuration manager for loading up token validations.
/// </summary>
internal class ConfigurationManager
{
public static Dictionary<string, ServiceInfo> SERVICES = new Dictionary<string, ServiceInfo>()
{
{ "99045fe1-7639-4a75-9d4a-577b6ca3810f", new ServiceInfo("https://login.microsoftonline.com","https://sts.windows.net/{0}/","https://login.microsoftonline.com/{0}/v2.0"){DefaultService=true } } //Public cloud
};

private const string BYPASS_VALIDATION = "AuthenticationEvents__BypassTokenValidation";
private const string CUSTOM_CALLER_APPID = "AuthenticationEvents__CustomCallerAppId";
internal const string TENANT_ID = "AuthenticationEvents__TenantId";
internal const string AUDIENCE_APPID = "AuthenticationEvents__AudienceAppId";
internal const string TOKEN_V1_VERIFY = "appid";
internal const string TOKEN_V2_VERIFY = "azp";
private const string OpenIdConfigurationPath = "/.well-known/openid-configuration";
private const string OpenIdConfigurationPathV2 = "/v2.0/.well-known/openid-configuration";

private const string AuthorityUrlKey = "AuthenticationEvents__AuthorityUrl";
private const string AuthorizedPartyAppIdKey = "AuthenticationEvents__AuthorizedPartyAppId";
private const string AudienceAppIdKey = "AuthenticationEvents__AudienceAppId";

private const string EZAUTH_ENABLED = "WEBSITE_AUTH_ENABLED";
private const string BYPASS_VALIDATION_KEY = "AuthenticationEvents__BypassTokenValidation";

internal const string AppIdKey = "appid";
internal const string AzpKey = "azp";

internal const string HEADER_EZAUTH_ICP = "X-MS-CLIENT-PRINCIPAL-IDP";
internal const string HEADER_EZAUTH_ICP_VERIFY = "aad";
internal const string HEADER_EZAUTH_PRINCIPAL = "X-MS-CLIENT-PRINCIPAL";

/// <summary>
/// Annotation for the trigger attribute.
/// </summary>
private readonly AuthenticationEventsTriggerAttribute triggerAttribute;

internal ConfigurationManager(AuthenticationEventsTriggerAttribute triggerAttribute)
{
this.triggerAttribute = triggerAttribute;
}

internal static bool BypassValidation => GetConfigValue(BYPASS_VALIDATION, false);
internal static bool EZAuthEnabled => GetConfigValue(EZAUTH_ENABLED, false);
internal static string CallerAppId => GetConfigValue(CUSTOM_CALLER_APPID, null);
internal string TenantId => GetConfigValue(TENANT_ID, triggerAttribute.TenantId);
internal string AudienceAppId => GetConfigValue(AUDIENCE_APPID, triggerAttribute.AudienceAppId);

internal static bool GetService(string serviceId, out ServiceInfo serviceInfo)
/// <summary>
/// Get the audience app id from the environment variable or use the default value from the trigger attribute.
/// REQUIRED FEILD
/// </summary>
internal string AudienceAppId
{
serviceInfo = null;
if (serviceId is null)
get
{
throw new ArgumentNullException(nameof(serviceId));
}
string value = GetConfigValue(AudienceAppIdKey, triggerAttribute?.AudienceAppId);

if (CallerAppId != null && serviceId.Equals(CallerAppId))
{
serviceInfo = SERVICES.Values.FirstOrDefault(x => x.DefaultService);
if (string.IsNullOrEmpty(value))
{
throw new MissingFieldException(
string.Format(
provider: CultureInfo.CurrentCulture,
format: AuthenticationEventResource.Ex_Trigger_ApplicationId_Required,
arg0: AudienceAppIdKey));
}

return value;
}
else if (SERVICES.ContainsKey(serviceId))
}

/// <summary>
/// Get the OpenId connection host from the environment variable or use the default value.
/// REQUIRD FEILD
/// </summary>
internal string AuthorityUrl
{
get
{
serviceInfo = SERVICES[serviceId];
}
string value = GetConfigValue(AuthorityUrlKey, triggerAttribute?.AuthorityUrl);

return serviceInfo != null;
if (string.IsNullOrEmpty(value))
{
throw new MissingFieldException(
string.Format(
provider: CultureInfo.CurrentCulture,
format: AuthenticationEventResource.Ex_Trigger_AuthorityUrl_Required,
arg0: AuthorityUrlKey));
}

return value;
}
}

internal static bool VerifyServiceId(string testId)
/// <summary>
/// Get the OpenId connection host from the environment variable or use the default value.
/// OPTIONAL FEILD, defaults to public cloud id.
/// </summary>
internal string AuthorizedPartyAppId
{
return GetService(testId, out _);
get
{
string value = GetConfigValue(AuthorizedPartyAppIdKey, triggerAttribute?.AuthorizedPartyAppId);

if (string.IsNullOrEmpty(value))
{
throw new MissingFieldException(
string.Format(
provider: CultureInfo.CurrentCulture,
format: AuthenticationEventResource.Ex_Trigger_AuthorizedPartyApplicationId_Required,
arg0: AuthorizedPartyAppIdKey));
}

return value;
}
}

/// <summary>
/// If we should bypass the token validation.
/// Use only for testing and development.
/// </summary>
internal bool BypassValidation => GetConfigValue(BYPASS_VALIDATION_KEY, false);

/// <summary>
/// If the EZAuth is enabled.
/// </summary>
internal bool EZAuthEnabled => GetConfigValue(EZAUTH_ENABLED, false);

/// <summary>
/// Get config value from environment variable or use the default value.
/// </summary>
/// <param name="environmentVariable">Definied Azure function application settings</param>
/// <param name="defaultValue">Default value, most likely from auth trigger anotation</param>
/// <returns></returns>
private static string GetConfigValue(string environmentVariable, string defaultValue)
{
return Environment.GetEnvironmentVariable(environmentVariable) ?? defaultValue;
}

private static T GetConfigValue<T>(string environmentVariable, T defaultValue) where T : struct
{
return Environment.GetEnvironmentVariable(environmentVariable) == null ?
string value = GetConfigValue(environmentVariable, null);

return value == null ?
defaultValue :
(T)Convert.ChangeType(Environment.GetEnvironmentVariable(environmentVariable), typeof(T), CultureInfo.CurrentCulture);
(T)Convert.ChangeType(
value: Environment.GetEnvironmentVariable(environmentVariable),
conversionType: typeof(T),
provider: CultureInfo.CurrentCulture);
}

/// <summary>
/// Get the issuer string based on the token schema version.
/// </summary>
/// <param name="tokenSchemaVersion">v2 will return v2 odic url, v1 will return v1</param>
/// <returns></returns>
internal string GetOpenIDConfigurationUrlString(SupportedTokenSchemaVersions tokenSchemaVersion)
{
return tokenSchemaVersion == SupportedTokenSchemaVersions.V2_0 ?
AuthorityUrl + OpenIdConfigurationPathV2 :
AuthorityUrl + OpenIdConfigurationPath;
}

/// <summary>
/// Validate the authorization party is accurate to the one in configuration.
/// </summary>
/// <param name="authoizedPartyValueFromTokenOrHeader">The value from either the token or the header.</param>
/// <returns>True if azp/appid value matches the configured value.</returns>
internal bool ValidateAuthorizationParty(string authoizedPartyValueFromTokenOrHeader)
{
return AuthorizedPartyAppId.EqualsOic(authoizedPartyValueFromTokenOrHeader);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
<ItemGroup>
<PackageReference Include="Microsoft.Azure.WebJobs" />
<PackageReference Include="Microsoft.AspNetCore.Http" />
<PackageReference Include="Microsoft.IdentityModel.Protocols.OpenIdConnect"/>
<PackageReference Include="Microsoft.IdentityModel.Tokens"/>
<PackageReference Include="System.IdentityModel.Tokens.Jwt" />
</ItemGroup>

Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,11 @@ namespace Microsoft.Azure.WebJobs.Extensions.AuthenticationEvents
internal enum SupportedTokenSchemaVersions
{
/// <summary>Version 1.</summary>
[Description("1.0")] V1_0,
[Description("1.0")]
V1_0,

/// <summary>Version 2.</summary>
[Description("2.0")] V2_0
[Description("2.0")]
V2_0
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,6 @@ namespace Microsoft.Azure.WebJobs.Extensions.AuthenticationEvents
{
internal abstract class TokenValidator
{
internal abstract Task<(bool Valid, Dictionary<string, string> Claims)> GetClaimsAndValidate(HttpRequestMessage request, ConfigurationManager configurationManager);
internal abstract Task<(bool Valid, Dictionary<string, string> Claims)> ValidateAndGetClaims(HttpRequestMessage request, ConfigurationManager configurationManager);
}
}
Loading
Loading