From 93f73d64c62b72ff7a0a4dc43cafb9e79801647e Mon Sep 17 00:00:00 2001 From: Jenny Ferries Date: Wed, 15 Jul 2020 19:56:14 -0700 Subject: [PATCH] fix build warnings --- src/Microsoft.Identity.Web/ITokenAcquisition.cs | 6 +++++- .../Microsoft.Identity.Web.xml | 12 +++++++++--- src/Microsoft.Identity.Web/TokenAcquisition.cs | 11 ++++++----- 3 files changed, 20 insertions(+), 9 deletions(-) diff --git a/src/Microsoft.Identity.Web/ITokenAcquisition.cs b/src/Microsoft.Identity.Web/ITokenAcquisition.cs index ab76c4d27..3f301db13 100644 --- a/src/Microsoft.Identity.Web/ITokenAcquisition.cs +++ b/src/Microsoft.Identity.Web/ITokenAcquisition.cs @@ -2,6 +2,7 @@ // Licensed under the MIT License. using System.Collections.Generic; +using System.Security.Claims; using System.Threading.Tasks; using Microsoft.AspNetCore.Http; using Microsoft.Identity.Client; @@ -21,8 +22,11 @@ public interface ITokenAcquisition /// Scopes to request for the downstream API to call. /// Enables to override the tenant/account for the same identity. This is useful in the /// cases where a given account is guest in other tenants, and you want to acquire tokens for a specific tenant. + /// Optional claims principal representing the user. If not provided, will use the signed-in + /// user (in a web app), or the user for which the token was received (in a web API) + /// cases where a given account is guest in other tenants, and you want to acquire tokens for a specific tenant, like where the user is a guest in. /// An access token to call on behalf of the user, the downstream API characterized by its scopes. - Task GetAccessTokenForUserAsync(IEnumerable scopes, string? tenantId = null); + Task GetAccessTokenForUserAsync(IEnumerable scopes, string? tenantId = null, ClaimsPrincipal? user = null); /// /// Acquires a token from the authority configured in the app, for the confidential client itself (not on behalf of a user) diff --git a/src/Microsoft.Identity.Web/Microsoft.Identity.Web.xml b/src/Microsoft.Identity.Web/Microsoft.Identity.Web.xml index 7027473e1..f715b8508 100644 --- a/src/Microsoft.Identity.Web/Microsoft.Identity.Web.xml +++ b/src/Microsoft.Identity.Web/Microsoft.Identity.Web.xml @@ -597,7 +597,7 @@ Interface for the token acquisition service (encapsulating MSAL.NET). - + Typically used from an ASP.NET Core Web App or Web API controller, this method gets an access token for a downstream API on behalf of the user account which claims are provided in the @@ -606,6 +606,9 @@ Scopes to request for the downstream API to call. Enables to override the tenant/account for the same identity. This is useful in the cases where a given account is guest in other tenants, and you want to acquire tokens for a specific tenant. + Optional claims principal representing the user. If not provided, will use the signed-in + user (in a web app), or the user for which the token was received (in a web API) + cases where a given account is guest in other tenants, and you want to acquire tokens for a specific tenant, like where the user is a guest in. An access token to call on behalf of the user, the downstream API characterized by its scopes. @@ -1372,7 +1375,7 @@ you have previously called AddAccountToCacheFromAuthorizationCodeAsync from a method called by OpenIdConnectOptions.Events.OnAuthorizationCodeReceived. - + Typically used from a Web App or WebAPI controller, this method retrieves an access token for a downstream API using; @@ -1384,8 +1387,11 @@ Scopes to request for the downstream API to call. Enables overriding of the tenant/account for the same identity. This is useful in the cases where a given account is guest in other tenants, and you want to acquire tokens for a specific tenant, like where the user is a guest in. + Optional claims principal representing the user. If not provided, will use the signed-in + user (in a web app), or the user for which the token was received (in a Web API) + cases where a given account is guest in other tenants, and you want to acquire tokens for a specific tenant, like where the user is a guest in. An access token to call the downstream API and populated with this downstream API's scopes. - Calling this method from a Web API supposes that you have previously called, + Calling this method from a web API supposes that you have previously called, in a method called by JwtBearerOptions.Events.OnTokenValidated, the HttpContextExtensions.StoreTokenUsedToCallWebAPI method passing the validated token (as a JwtSecurityToken). Calling it from a Web App supposes that you have previously called AddAccountToCacheFromAuthorizationCodeAsync from a method called by diff --git a/src/Microsoft.Identity.Web/TokenAcquisition.cs b/src/Microsoft.Identity.Web/TokenAcquisition.cs index ffc9b4ded..0ada75632 100644 --- a/src/Microsoft.Identity.Web/TokenAcquisition.cs +++ b/src/Microsoft.Identity.Web/TokenAcquisition.cs @@ -180,11 +180,12 @@ public async Task GetAccessTokenOnBehalfOfUserAsync( /// /// Scopes to request for the downstream API to call. /// Enables overriding of the tenant/account for the same identity. This is useful in the - /// Optional claims principal representing the user. If not provided, will use the signed-in - /// user (in a Web app), or the user for which the token was received (in a Web API) + /// cases where a given account is guest in other tenants, and you want to acquire tokens for a specific tenant, like where the user is a guest in. + /// Optional claims principal representing the user. If not provided, will use the signed-in + /// user (in a web app), or the user for which the token was received (in a Web API) /// cases where a given account is guest in other tenants, and you want to acquire tokens for a specific tenant, like where the user is a guest in. /// An access token to call the downstream API and populated with this downstream API's scopes. - /// Calling this method from a Web API supposes that you have previously called, + /// Calling this method from a web API supposes that you have previously called, /// in a method called by JwtBearerOptions.Events.OnTokenValidated, the HttpContextExtensions.StoreTokenUsedToCallWebAPI method /// passing the validated token (as a JwtSecurityToken). Calling it from a Web App supposes that /// you have previously called AddAccountToCacheFromAuthorizationCodeAsync from a method called by @@ -330,7 +331,7 @@ private async Task GetOrBuildConfidentialClientA private async Task BuildConfidentialClientApplicationAsync() { var request = CurrentHttpContext?.Request; - string currentUri = null; + string? currentUri = null; if (request != null) { currentUri = UriHelper.BuildAbsolute( @@ -356,7 +357,7 @@ private async Task BuildConfidentialClientApplic .WithHttpClientFactory(_httpClientFactory); // The redirect URI is not needed for OBO - if (currentUri != null) + if (!string.IsNullOrEmpty(currentUri)) { builder.WithRedirectUri(currentUri); }