Skip to content

Commit

Permalink
fix PR feedback for xml comments and constants (#442)
Browse files Browse the repository at this point in the history
* fix PR feedback for xml comments and constants
* fix spelling + add more const
  • Loading branch information
jennyf19 authored Aug 13, 2020
1 parent 14e1f35 commit 789fd51
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 12 deletions.
7 changes: 6 additions & 1 deletion src/Microsoft.Identity.Web/Constants/Constants.cs
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,13 @@ 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
public const string UserReadScope = "user.read";
public const string GraphBaseUrlV1 = "https://graph.microsoft.com/v1.0";
}
}
1 change: 1 addition & 0 deletions src/Microsoft.Identity.Web/Constants/IDWebErrorMessage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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. ";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,16 @@
namespace Microsoft.Identity.Web
{
/// <summary>
/// Extensions methods on a MicrososoftAppCallingWebApiAuthenticationBuilder builder
/// Extensions methods on a MicrosoftIdentityAppCallingWebApiAuthenticationBuilder builder
/// to add support to call Microsoft Graph.
/// </summary>
public static class MicrosoftGraphServiceExtensions
{
/// <summary>
/// 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.
/// </summary>
/// <param name="builder">Builder.</param>
/// <param name="configurationSection">Configuraiton section.</param>
/// <param name="configurationSection">Configuration section.</param>
/// <returns>The builder to chain.</returns>
public static MicrosoftIdentityAppCallsWebApiAuthenticationBuilder AddMicrosoftGraphServiceClient(
this MicrosoftIdentityAppCallsWebApiAuthenticationBuilder builder,
Expand All @@ -30,16 +30,16 @@ public static MicrosoftIdentityAppCallsWebApiAuthenticationBuilder AddMicrosoftG
}

/// <summary>
/// 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.
/// </summary>
/// <param name="builder">Builder.</param>
/// <param name="graphBaseUrl">Named instance of option.</param>
/// <param name="defaultScopes">Configuraiton section.</param>
/// <param name="defaultScopes">Configuration section.</param>
/// <returns>The builder to chain.</returns>
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 =>
Expand All @@ -50,7 +50,7 @@ public static MicrosoftIdentityAppCallsWebApiAuthenticationBuilder AddMicrosoftG
}

/// <summary>
/// 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.
/// </summary>
/// <param name="builder">Builder.</param>
/// <param name="configureMicrosoftGraphOptions">Method to configure the options.</param>
Expand All @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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)));
}
}
}

0 comments on commit 789fd51

Please sign in to comment.