-
Notifications
You must be signed in to change notification settings - Fork 219
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implemented C# 8 Nullable Reference Type standard. Includes additiona…
…l null checks for public method parameters. Minor comment fixes.
- Loading branch information
Showing
51 changed files
with
471 additions
and
313 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,36 +1,46 @@ | ||
// Copyright (c) Microsoft Corporation. All rights reserved. | ||
// Licensed under the MIT License. | ||
|
||
using System; | ||
using System.Security.Claims; | ||
using Microsoft.Identity.Client; | ||
|
||
namespace Microsoft.Identity.Web | ||
{ | ||
/// <summary> | ||
/// Extension methods dealing with IAccount instances. | ||
/// Extension methods for <see cref="IAccount"/>. | ||
/// </summary> | ||
public static class AccountExtensions | ||
{ | ||
/// <summary> | ||
/// Creates the <see cref="ClaimsPrincipal"/> from the values found | ||
/// in an <see cref="IAccount"/>. | ||
/// </summary> | ||
/// <param name="account">The IAccount instance.</param> | ||
/// <returns>A <see cref="ClaimsPrincipal"/> built from IAccount.</returns> | ||
/// <param name="account">The <see cref="IAccount"/> instance.</param> | ||
/// <returns>A <see cref="ClaimsPrincipal"/> built from <see cref="IAccount"/>.</returns> | ||
public static ClaimsPrincipal ToClaimsPrincipal(this IAccount account) | ||
{ | ||
if (account != null) | ||
if (account == null) | ||
{ | ||
return new ClaimsPrincipal( | ||
new ClaimsIdentity(new Claim[] | ||
{ | ||
new Claim(ClaimConstants.Oid, account.HomeAccountId?.ObjectId), | ||
new Claim(ClaimConstants.Tid, account.HomeAccountId?.TenantId), | ||
new Claim(ClaimTypes.Upn, account.Username), | ||
})); | ||
throw new ArgumentNullException(nameof(account)); | ||
} | ||
|
||
return null; | ||
ClaimsIdentity identity = new ClaimsIdentity(new Claim[] | ||
{ | ||
new Claim(ClaimTypes.Upn, account.Username), | ||
}); | ||
|
||
if (!string.IsNullOrEmpty(account.HomeAccountId?.ObjectId)) | ||
{ | ||
identity.AddClaim(new Claim(ClaimConstants.Oid, account.HomeAccountId.ObjectId)); | ||
} | ||
|
||
if (!string.IsNullOrEmpty(account.HomeAccountId?.TenantId)) | ||
{ | ||
identity.AddClaim(new Claim(ClaimConstants.Tid, account.HomeAccountId.TenantId)); | ||
} | ||
|
||
return new ClaimsPrincipal(identity); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.