Skip to content

Commit 6aa9241

Browse files
authored
Remove all TSA warnings (#2037)
Adds EditorBrowsable(Never) attributes for the methods that were obsoleted Auth code flow redemption now also provides the access token (#1771)
1 parent 08d110b commit 6aa9241

File tree

69 files changed

+281
-164
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

69 files changed

+281
-164
lines changed

src/Microsoft.Identity.Web.OWIN/AppBuilderExtension.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,7 @@ public static IAppBuilder AddMicrosoftIdentityWebApp(
189189
context.TokenEndpointRequest.Parameters.TryGetValue("code_verifier", out string codeVerifier);
190190
var tokenAcquisition = tokenAcquirerFactory?.ServiceProvider?.GetRequiredService<ITokenAcquisitionInternal>();
191191
var msIdentityOptions = tokenAcquirerFactory?.ServiceProvider?.GetRequiredService<IOptions<MicrosoftIdentityOptions>>();
192-
var idToken = await (tokenAcquisition!.AddAccountToCacheFromAuthorizationCodeAsync(
192+
var result = await (tokenAcquisition!.AddAccountToCacheFromAuthorizationCodeAsync(
193193
new string[] { options.Scope },
194194
context.Code,
195195
string.Empty,
@@ -198,7 +198,7 @@ public static IAppBuilder AddMicrosoftIdentityWebApp(
198198
msIdentityOptions?.Value.DefaultUserFlow)).ConfigureAwait(false);
199199
HttpContextBase httpContext = context.OwinContext.Get<HttpContextBase>(typeof(HttpContextBase).FullName);
200200
httpContext.Session.Add(ClaimConstants.ClientInfo, context.ProtocolMessage.GetParameter(ClaimConstants.ClientInfo));
201-
context.HandleCodeRedemption(null, idToken);
201+
context.HandleCodeRedemption(result.AccessToken, result.IdToken);
202202
};
203203

204204
updateOptions?.Invoke(options);

src/Microsoft.Identity.Web.TokenAcquisition/AspNetCore/TokenAcquisition-AspnetCore.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -151,8 +151,8 @@ public async Task AddAccountToCacheFromAuthorizationCodeAsync(
151151
string authCode = context!.ProtocolMessage!.Code;
152152
string? userFlow = context.Principal?.GetUserFlowId();
153153

154-
string idToken = await AddAccountToCacheFromAuthorizationCodeAsync(scopes, authCode, authenticationScheme, clientInfo, codeVerifier, userFlow).ConfigureAwait(false);
155-
context.HandleCodeRedemption(null, idToken);
154+
AcquireTokenResult result = await AddAccountToCacheFromAuthorizationCodeAsync(scopes, authCode, authenticationScheme, clientInfo, codeVerifier, userFlow).ConfigureAwait(false);
155+
context.HandleCodeRedemption(result.AccessToken!, result.IdToken!);
156156
}
157157

158158
TokenAcquirerFactory_GetTokenAcquirers? _implementation;

src/Microsoft.Identity.Web.TokenAcquisition/Base64UrlHelpers.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ internal static class Base64UrlHelpers
3636
/// </summary>
3737
/// <param name="arg">string to encode.</param>
3838
/// <returns>Base64Url encoding of the UTF8 bytes.</returns>
39-
public static string? Encode(string arg)
39+
public static string? Encode(string? arg)
4040
{
4141
if (arg == null)
4242
{
@@ -143,7 +143,7 @@ private static string Encode(byte[] inArray, int offset, int length)
143143
/// <returns>The string representation in base 64 url encoding of length elements of inArray, starting at position offset.</returns>
144144
/// <exception cref="ArgumentNullException">'inArray' is null.</exception>
145145
/// <exception cref="ArgumentOutOfRangeException">offset or length is negative OR offset plus length is greater than the length of inArray.</exception>
146-
public static string? Encode(byte[] inArray)
146+
public static string? Encode(byte[]? inArray)
147147
{
148148
if (inArray == null)
149149
{
@@ -153,7 +153,7 @@ private static string Encode(byte[] inArray, int offset, int length)
153153
return Encode(inArray, 0, inArray.Length);
154154
}
155155

156-
internal static string? EncodeString(string str)
156+
internal static string? EncodeString(string? str)
157157
{
158158
if (str == null)
159159
{
@@ -167,7 +167,7 @@ private static string Encode(byte[] inArray, int offset, int length)
167167
/// Converts the specified string, which encodes binary data as base-64-url digits, to an equivalent 8-bit unsigned integer array.</summary>
168168
/// <param name="str">base64Url encoded string.</param>
169169
/// <returns>UTF8 bytes.</returns>
170-
public static byte[]? DecodeBytes(string str)
170+
public static byte[]? DecodeBytes(string? str)
171171
{
172172
if (str == null)
173173
{

src/Microsoft.Identity.Web.TokenAcquisition/ClientInfo.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ internal class ClientInfo
1616
[JsonPropertyName(ClaimConstants.UniqueTenantIdentifier)]
1717
public string? UniqueTenantIdentifier { get; set; } = null;
1818

19-
public static ClientInfo? CreateFromJson(string clientInfo)
19+
public static ClientInfo? CreateFromJson(string? clientInfo)
2020
{
2121
if (string.IsNullOrEmpty(clientInfo))
2222
{
@@ -27,7 +27,7 @@ internal class ClientInfo
2727
return bytes != null ? DeserializeFromJson(bytes) : null;
2828
}
2929

30-
internal static ClientInfo? DeserializeFromJson(byte[] jsonByteArray)
30+
internal static ClientInfo? DeserializeFromJson(byte[]? jsonByteArray)
3131
{
3232
if (jsonByteArray == null || jsonByteArray.Length == 0)
3333
{

src/Microsoft.Identity.Web.TokenAcquisition/ITokenAcquisitionInternal.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
using Microsoft.AspNetCore.Authentication.OpenIdConnect;
99
#endif
1010

11+
using Microsoft.Identity.Abstractions;
12+
1113
namespace Microsoft.Identity.Web
1214
{
1315
/// <summary>
@@ -63,8 +65,8 @@ Task AddAccountToCacheFromAuthorizationCodeAsync(
6365
/// <param name="clientInfo">Client Info obtained with the code</param>
6466
/// <param name="codeVerifier">PKCE code verifier</param>
6567
/// <param name="userFlow">User flow in the case of B2C</param>
66-
/// <returns>The ID Token.</returns>
67-
Task<string> AddAccountToCacheFromAuthorizationCodeAsync(
68+
/// <returns>The token acquirer result.</returns>
69+
Task<AcquireTokenResult> AddAccountToCacheFromAuthorizationCodeAsync(
6870
IEnumerable<string> scopes,
6971
string authCode,
7072
string authenticationScheme,

src/Microsoft.Identity.Web.TokenAcquisition/TokenAcquisition.cs

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ public TokenAcquisition(
102102
_credentialsLoader = credentialsLoader;
103103
}
104104

105-
public async Task<string> AddAccountToCacheFromAuthorizationCodeAsync(
105+
public async Task<AcquireTokenResult> AddAccountToCacheFromAuthorizationCodeAsync(
106106
IEnumerable<string> scopes,
107107
string authCode,
108108
string authenticationScheme,
@@ -124,7 +124,7 @@ public async Task<string> AddAccountToCacheFromAuthorizationCodeAsync(
124124
string? backUpAuthRoutingHint = string.Empty;
125125
if (!string.IsNullOrEmpty(clientInfo))
126126
{
127-
ClientInfo? clientInfoFromAuthorize = ClientInfo.CreateFromJson(clientInfo!);
127+
ClientInfo? clientInfoFromAuthorize = ClientInfo.CreateFromJson(clientInfo);
128128
if (clientInfoFromAuthorize != null && clientInfoFromAuthorize.UniqueTenantIdentifier != null && clientInfoFromAuthorize.UniqueObjectIdentifier != null)
129129
{
130130
backUpAuthRoutingHint = $"oid:{clientInfoFromAuthorize.UniqueObjectIdentifier}@{clientInfoFromAuthorize.UniqueTenantIdentifier}";
@@ -153,7 +153,14 @@ public async Task<string> AddAccountToCacheFromAuthorizationCodeAsync(
153153
_tokenAcquisitionHost.SetSession(Constants.SpaAuthCode, result.SpaAuthCode);
154154
}
155155

156-
return result.IdToken;
156+
return new AcquireTokenResult(
157+
result.AccessToken,
158+
result.ExpiresOn,
159+
result.TenantId,
160+
result.IdToken,
161+
result.Scopes,
162+
result.CorrelationId,
163+
result.TokenType);
157164
}
158165
catch (MsalServiceException exMsal) when (IsInvalidClientCertificateError(exMsal))
159166
{
@@ -162,7 +169,7 @@ public async Task<string> AddAccountToCacheFromAuthorizationCodeAsync(
162169

163170
// Retry
164171
_retryClientCertificate = true;
165-
await AddAccountToCacheFromAuthorizationCodeAsync(scopes, authCode, authenticationScheme, clientInfo, codeVerifier, userFlow).ConfigureAwait(false);
172+
return await AddAccountToCacheFromAuthorizationCodeAsync(scopes, authCode, authenticationScheme, clientInfo, codeVerifier, userFlow).ConfigureAwait(false);
166173
}
167174
catch (MsalException ex)
168175
{
@@ -173,8 +180,6 @@ public async Task<string> AddAccountToCacheFromAuthorizationCodeAsync(
173180
{
174181
_retryClientCertificate = false;
175182
}
176-
177-
return authenticationScheme;
178183
}
179184

180185
private static string GetApplicationKey(MergedOptions mergedOptions)

src/Microsoft.Identity.Web.TokenCache/Distributed/MsalDistributedTokenCacheAdapter.cs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -223,7 +223,7 @@ protected override async Task WriteCacheBytesAsync(string cacheKey, byte[] bytes
223223
protected override async Task WriteCacheBytesAsync(
224224
string cacheKey,
225225
byte[] bytes,
226-
CacheSerializerHints cacheSerializerHints)
226+
CacheSerializerHints? cacheSerializerHints)
227227
{
228228
const string write = "Write";
229229

@@ -263,7 +263,8 @@ await L2OperationWithRetryOnFailureAsync(
263263
write,
264264
(cacheKey) => _distributedCache.SetAsync(
265265
cacheKey,
266-
bytes,
266+
bytes!, // We know that in the Write case, the bytes won't be null
267+
// the parent class
267268
distributedCacheEntryOptions,
268269
cacheSerializerHints?.CancellationToken ?? CancellationToken.None),
269270
cacheKey).Measure().ConfigureAwait(false);
@@ -275,7 +276,7 @@ await L2OperationWithRetryOnFailureAsync(
275276
write,
276277
(cacheKey) => _distributedCache.SetAsync(
277278
cacheKey,
278-
bytes,
279+
bytes!,
279280
distributedCacheEntryOptions,
280281
cacheSerializerHints?.CancellationToken ?? CancellationToken.None),
281282
cacheKey).Measure().ConfigureAwait(false));

src/Microsoft.Identity.Web/DownstreamWebApiSupport/DownstreamWebApi.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
// Licensed under the MIT License.
33

44
using System;
5+
using System.ComponentModel;
56
using System.Net.Http;
67
using System.Security.Claims;
78
using System.Text;
@@ -16,7 +17,12 @@ namespace Microsoft.Identity.Web
1617
/// <summary>
1718
/// Implementation for the downstream web API.
1819
/// </summary>
20+
#pragma warning disable CS0618 // Type or member is obsolete
21+
[Obsolete("Use DownstreamRestApi in Microsoft.Identity.Abstractions, implemented in Microsoft.Identity.Web.DownstreamRestApi." +
22+
"See aka.ms/id-web-downstream-api-v2 for migration details.", false)]
23+
[EditorBrowsable(EditorBrowsableState.Never)]
1924
public class DownstreamWebApi : IDownstreamWebApi
25+
#pragma warning restore CS0618 // Type or member is obsolete
2026
{
2127
private readonly ITokenAcquisition _tokenAcquisition;
2228
private readonly HttpClient _httpClient;

src/Microsoft.Identity.Web/DownstreamWebApiSupport/DownstreamWebApiExtensions.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
// Licensed under the MIT License.
33

44
using System;
5+
using System.ComponentModel;
56
using Microsoft.Extensions.Configuration;
67
using Microsoft.Extensions.DependencyInjection;
78

@@ -22,6 +23,7 @@ public static class DownstreamWebApiExtensions
2223
/// <returns>The builder for chaining.</returns>
2324
[Obsolete("Use AddDownstreamRestApi in Microsoft.Identity.Abstractions, implemented in Microsoft.Identity.Web.DownstreamRestApi." +
2425
"See aka.ms/id-web-downstream-api-v2 for migration details.", false)]
26+
[EditorBrowsable(EditorBrowsableState.Never)]
2527
public static MicrosoftIdentityAppCallsWebApiAuthenticationBuilder AddDownstreamWebApi(
2628
this MicrosoftIdentityAppCallsWebApiAuthenticationBuilder builder,
2729
string serviceName,
@@ -44,6 +46,7 @@ public static MicrosoftIdentityAppCallsWebApiAuthenticationBuilder AddDownstream
4446
/// <returns>The builder for chaining.</returns>
4547
[Obsolete("Use AddDownstreamRestApi in Microsoft.Identity.Abstractions, implemented in Microsoft.Identity.Web.DownstreamRestApi." +
4648
"See aka.ms/id-web-downstream-api-v2 for migration details.", false)]
49+
[EditorBrowsable(EditorBrowsableState.Never)]
4750
public static MicrosoftIdentityAppCallsWebApiAuthenticationBuilder AddDownstreamWebApi(
4851
this MicrosoftIdentityAppCallsWebApiAuthenticationBuilder builder,
4952
string serviceName,

src/Microsoft.Identity.Web/DownstreamWebApiSupport/DownstreamWebApiGenericExtensions.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
// Licensed under the MIT License.
33

44
using System;
5+
using System.ComponentModel;
56
using System.Net.Http;
67
using System.Security.Claims;
78
using System.Text;
@@ -35,6 +36,7 @@ public static class DownstreamWebApiGenericExtensions
3536
/// <returns>A strongly typed response from the web API.</returns>
3637
[Obsolete("Use IDownstreamRestApi.GetForUserAsync in Microsoft.Identity.Abstractions, implemented in Microsoft.Identity.Web.DownstreamRestApi." +
3738
"See aka.ms/id-web-downstream-api-v2 for migration details.", false)]
39+
[EditorBrowsable(EditorBrowsableState.Never)]
3840
public static async Task<TOutput?> GetForUserAsync<TOutput>(
3941
this IDownstreamWebApi downstreamWebApi,
4042
string serviceName,
@@ -75,6 +77,7 @@ public static class DownstreamWebApiGenericExtensions
7577
/// <returns>The value returned by the downstream web API.</returns>
7678
[Obsolete("Use IDownstreamRestApi.GetForUserAsync in Microsoft.Identity.Abstractions, implemented in Microsoft.Identity.Web.DownstreamRestApi." +
7779
"See aka.ms/id-web-downstream-api-v2 for migration details.", false)]
80+
[EditorBrowsable(EditorBrowsableState.Never)]
7881
public static async Task GetForUserAsync<TInput>(
7982
this IDownstreamWebApi downstreamWebApi,
8083
string serviceName,
@@ -118,6 +121,7 @@ await downstreamWebApi.CallWebApiForUserAsync(
118121
/// <returns>A strongly typed response from the web API.</returns>
119122
[Obsolete("Use IDownstreamRestApi.PostForUserAsync in Microsoft.Identity.Abstractions, implemented in Microsoft.Identity.Web.DownstreamRestApi." +
120123
"See aka.ms/id-web-downstream-api-v2 for migration details.", false)]
124+
[EditorBrowsable(EditorBrowsableState.Never)]
121125
public static async Task<TOutput?> PostForUserAsync<TOutput, TInput>(
122126
this IDownstreamWebApi downstreamWebApi,
123127
string serviceName,
@@ -163,6 +167,7 @@ await downstreamWebApi.CallWebApiForUserAsync(
163167
/// <returns>The value returned by the downstream web API.</returns>
164168
[Obsolete("Use IDownstreamRestApi.PutForUserAsync in Microsoft.Identity.Abstractions, implemented in Microsoft.Identity.Web.DownstreamRestApi." +
165169
"See aka.ms/id-web-downstream-api-v2 for migration details.", false)]
170+
[EditorBrowsable(EditorBrowsableState.Never)]
166171
public static async Task PutForUserAsync<TInput>(
167172
this IDownstreamWebApi downstreamWebApi,
168173
string serviceName,
@@ -207,6 +212,7 @@ await downstreamWebApi.CallWebApiForUserAsync(
207212
/// <returns>A strongly typed response from the web API.</returns>
208213
[Obsolete("Use IDownstreamRestApi.PutForUserAsync in Microsoft.Identity.Abstractions, implemented in Microsoft.Identity.Web.DownstreamRestApi." +
209214
"See aka.ms/id-web-downstream-api-v2 for migration details.", false)]
215+
[EditorBrowsable(EditorBrowsableState.Never)]
210216
public static async Task<TOutput?> PutForUserAsync<TOutput, TInput>(
211217
this IDownstreamWebApi downstreamWebApi,
212218
string serviceName,
@@ -251,6 +257,7 @@ await downstreamWebApi.CallWebApiForUserAsync(
251257
/// <returns>The value returned by the downstream web API.</returns>
252258
[Obsolete("Use IDownstreamRestApi.CallWebApiForUserAsync in Microsoft.Identity.Abstractions, implemented in Microsoft.Identity.Web.DownstreamRestApi." +
253259
"See aka.ms/id-web-downstream-api-v2 for migration details.", false)]
260+
[EditorBrowsable(EditorBrowsableState.Never)]
254261
public static async Task<TOutput?> CallWebApiForUserAsync<TOutput>(
255262
this IDownstreamWebApi downstreamWebApi,
256263
string serviceName,

0 commit comments

Comments
 (0)