From 5e4be1c4789e3b09569018c6a943feeb7ddd4696 Mon Sep 17 00:00:00 2001 From: Jenny Ferries Date: Wed, 12 Aug 2020 16:41:36 -0700 Subject: [PATCH 1/2] fix PR feedback for xml comments and constants --- .../Constants/Constants.cs | 4 ++++ .../Constants/IDWebErrorMessage.cs | 1 + .../MicrosoftGraphServiceExtensions.cs | 18 +++++++++--------- 3 files changed, 14 insertions(+), 9 deletions(-) diff --git a/src/Microsoft.Identity.Web/Constants/Constants.cs b/src/Microsoft.Identity.Web/Constants/Constants.cs index e417617ad..c5ab3ec0f 100644 --- a/src/Microsoft.Identity.Web/Constants/Constants.cs +++ b/src/Microsoft.Identity.Web/Constants/Constants.cs @@ -61,5 +61,9 @@ internal static class Constants // Blazor challenge uri public const string BlazorChallengeUri = "MicrosoftIdentity/Account/Challenge?redirectUri="; + + // Microsoft Graph + public const string UserReadScope = "user.read"; + public const string GraphBaseUrlV1 = "https://graph.microsoft.com/v1.0"; } } diff --git a/src/Microsoft.Identity.Web/Constants/IDWebErrorMessage.cs b/src/Microsoft.Identity.Web/Constants/IDWebErrorMessage.cs index 41355123c..5c6eb766f 100644 --- a/src/Microsoft.Identity.Web/Constants/IDWebErrorMessage.cs +++ b/src/Microsoft.Identity.Web/Constants/IDWebErrorMessage.cs @@ -31,6 +31,7 @@ internal static class IDWebErrorMessage public const string UnauthenticatedUser = "IDW10204:The user is unauthenticated. The HttpContext does not contain any claims. "; public const string BlazorServerBaseUriNotSet = "IDW10205: Using Blazor server but the base URI was not properly set. "; public const string BlazorServerUserNotSet = "IDW10206: Using Blazor server but the user was not properly set. "; + public const string CalledApiScopesAreNull = "IDW10207: The CalledApiScopes cannot be null. "; // Token Validation IDW10300 = "IDW10300:" public const string IssuerMetadataUrlIsRequired = "IDW10301: Azure AD Issuer metadata address URL is required. "; diff --git a/src/Microsoft.Identity.Web/MicrosoftGraph/MicrosoftGraphServiceExtensions.cs b/src/Microsoft.Identity.Web/MicrosoftGraph/MicrosoftGraphServiceExtensions.cs index af08ebb5c..0a1c76b07 100644 --- a/src/Microsoft.Identity.Web/MicrosoftGraph/MicrosoftGraphServiceExtensions.cs +++ b/src/Microsoft.Identity.Web/MicrosoftGraph/MicrosoftGraphServiceExtensions.cs @@ -10,16 +10,16 @@ namespace Microsoft.Identity.Web { /// - /// Extensions methods on a MicrososoftAppCallingWebApiAuthenticationBuilder builder + /// Extensions methods on a MicrososoftIdentityAppCallingWebApiAuthenticationBuilder builder /// to add support to call Microsoft Graph. /// public static class MicrosoftGraphServiceExtensions { /// - /// Add support to calls Microsoft graph. From a named option and a configuration section. + /// Add support to call Microsoft Graph. From a named option and a configuration section. /// /// Builder. - /// Configuraiton section. + /// Configuration section. /// The builder to chain. public static MicrosoftIdentityAppCallsWebApiAuthenticationBuilder AddMicrosoftGraphServiceClient( this MicrosoftIdentityAppCallsWebApiAuthenticationBuilder builder, @@ -30,16 +30,16 @@ public static MicrosoftIdentityAppCallsWebApiAuthenticationBuilder AddMicrosoftG } /// - /// Add support to calls Microsoft graph. From a base graph Url and a default scope. + /// Add support to call Microsoft Graph. From a base Graph URL and a default scope. /// /// Builder. /// Named instance of option. - /// Configuraiton section. + /// Configuration section. /// The builder to chain. public static MicrosoftIdentityAppCallsWebApiAuthenticationBuilder AddMicrosoftGraphServiceClient( this MicrosoftIdentityAppCallsWebApiAuthenticationBuilder builder, - string graphBaseUrl = "https://graph.microsoft.com/v1.0", - string defaultScopes = "user.read") + string graphBaseUrl = Constants.GraphBaseUrlV1, + string defaultScopes = Constants.UserReadScope) { return builder.AddMicrosoftGraphServiceClient( options => @@ -50,7 +50,7 @@ public static MicrosoftIdentityAppCallsWebApiAuthenticationBuilder AddMicrosoftG } /// - /// Add support to calls Microsoft graph. From a named options and a configuraiton method. + /// Add support to call Microsoft Graph. From a named options and a configuration method. /// /// Builder. /// Method to configure the options. @@ -76,7 +76,7 @@ public static MicrosoftIdentityAppCallsWebApiAuthenticationBuilder AddMicrosoftG var microsoftGraphOptions = options.Value; if (microsoftGraphOptions.Scopes == null) { - throw new ArgumentException("CalledApiScopes should not be null."); + throw new ArgumentException(IDWebErrorMessage.CalledApiScopesAreNull); } string graphBaseUrl = microsoftGraphOptions.BaseUrl; From 85271ee0276d0af45ebb4b7832ca581f52144ac4 Mon Sep 17 00:00:00 2001 From: Jenny Ferries Date: Wed, 12 Aug 2020 20:17:36 -0700 Subject: [PATCH 2/2] fix spelling + add more const --- src/Microsoft.Identity.Web/Constants/Constants.cs | 3 ++- .../MicrosoftGraph/MicrosoftGraphServiceExtensions.cs | 2 +- .../MicrosoftGraph/TokenAcquisitionCredentialProvider.cs | 9 +++++++-- 3 files changed, 10 insertions(+), 4 deletions(-) diff --git a/src/Microsoft.Identity.Web/Constants/Constants.cs b/src/Microsoft.Identity.Web/Constants/Constants.cs index c5ab3ec0f..377475bb6 100644 --- a/src/Microsoft.Identity.Web/Constants/Constants.cs +++ b/src/Microsoft.Identity.Web/Constants/Constants.cs @@ -58,8 +58,9 @@ internal static class Constants public const string Bearer = "Bearer"; public const string LoginHint = "loginHint"; public const string DomainHint = "domainHint"; + public const string Authorization = "Authorization"; - // Blazor challenge uri + // Blazor challenge URI public const string BlazorChallengeUri = "MicrosoftIdentity/Account/Challenge?redirectUri="; // Microsoft Graph diff --git a/src/Microsoft.Identity.Web/MicrosoftGraph/MicrosoftGraphServiceExtensions.cs b/src/Microsoft.Identity.Web/MicrosoftGraph/MicrosoftGraphServiceExtensions.cs index 0a1c76b07..404c98da4 100644 --- a/src/Microsoft.Identity.Web/MicrosoftGraph/MicrosoftGraphServiceExtensions.cs +++ b/src/Microsoft.Identity.Web/MicrosoftGraph/MicrosoftGraphServiceExtensions.cs @@ -10,7 +10,7 @@ namespace Microsoft.Identity.Web { /// - /// Extensions methods on a MicrososoftIdentityAppCallingWebApiAuthenticationBuilder builder + /// Extensions methods on a MicrosoftIdentityAppCallingWebApiAuthenticationBuilder builder /// to add support to call Microsoft Graph. /// public static class MicrosoftGraphServiceExtensions diff --git a/src/Microsoft.Identity.Web/MicrosoftGraph/TokenAcquisitionCredentialProvider.cs b/src/Microsoft.Identity.Web/MicrosoftGraph/TokenAcquisitionCredentialProvider.cs index 73a8681d0..59e5594bd 100644 --- a/src/Microsoft.Identity.Web/MicrosoftGraph/TokenAcquisitionCredentialProvider.cs +++ b/src/Microsoft.Identity.Web/MicrosoftGraph/TokenAcquisitionCredentialProvider.cs @@ -2,6 +2,7 @@ // Licensed under the MIT License. using System.Collections.Generic; +using System.Globalization; using System.Net.Http; using System.Threading.Tasks; using Microsoft.Graph; @@ -30,8 +31,12 @@ public TokenAcquisitionCredentialProvider(ITokenAcquisition tokenAcquisition, IE public async Task AuthenticateRequestAsync(HttpRequestMessage request) { request.Headers.Add( - "Authorization", - $"Bearer {await _tokenAcquisition.GetAccessTokenForUserAsync(_initialScopes).ConfigureAwait(false)}"); + Constants.Authorization, + string.Format( + CultureInfo.InvariantCulture, + "{0}{1}", + Constants.Bearer, + await _tokenAcquisition.GetAccessTokenForUserAsync(_initialScopes).ConfigureAwait(false))); } } }