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

fix PR feedback for xml comments and constants #442

Merged
merged 2 commits into from
Aug 13, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
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)));
}
}
}