diff --git a/src/Microsoft.AspNet.Identity.Authentication/IdentityExtensions.cs b/src/Microsoft.AspNet.Identity.Authentication/IdentityExtensions.cs deleted file mode 100644 index e99637493d..0000000000 --- a/src/Microsoft.AspNet.Identity.Authentication/IdentityExtensions.cs +++ /dev/null @@ -1,59 +0,0 @@ -// Copyright (c) Microsoft Open Technologies, Inc. All rights reserved. -// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. - -using System.Security.Claims; - -namespace System.Security.Principal -{ - /// - /// Extensions making it easier to get the user name/user id claims off of an identity - /// - public static class IdentityExtensions - { - /// - /// Return the user name using the UserNameClaimType - /// - /// - /// - public static string GetUserName(this IIdentity identity) - { - if (identity == null) - { - throw new ArgumentNullException("identity"); - } - var ci = identity as ClaimsIdentity; - return ci != null ? ci.FindFirstValue(ClaimsIdentity.DefaultNameClaimType) : null; - } - - /// - /// Return the user id using the UserIdClaimType - /// - /// - /// - public static string GetUserId(this IIdentity identity) - { - if (identity == null) - { - throw new ArgumentNullException("identity"); - } - var ci = identity as ClaimsIdentity; - return ci != null ? ci.FindFirstValue(ClaimTypes.NameIdentifier) : null; - } - - /// - /// Return the claim value for the first claim with the specified type if it exists, null otherwise - /// - /// - /// - /// - public static string FindFirstValue(this ClaimsIdentity identity, string claimType) - { - if (identity == null) - { - throw new ArgumentNullException("identity"); - } - var claim = identity.FindFirst(claimType); - return claim != null ? claim.Value : null; - } - } -} \ No newline at end of file diff --git a/test/Microsoft.AspNet.Identity.Authentication.Test/IdentityExtensionsTest.cs b/test/Microsoft.AspNet.Identity.Authentication.Test/IdentityExtensionsTest.cs deleted file mode 100644 index 0b42b7f813..0000000000 --- a/test/Microsoft.AspNet.Identity.Authentication.Test/IdentityExtensionsTest.cs +++ /dev/null @@ -1,77 +0,0 @@ -// Copyright (c) Microsoft Open Technologies, Inc. All rights reserved. -// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. - -using System; -using System.Security.Claims; -using System.Security.Principal; -using Xunit; - -namespace Microsoft.AspNet.Identity.Authentication.Test -{ - public class IdentityExtensionsTest - { - public const string ExternalAuthenticationType = "TestExternalAuth"; - - [Fact] - public void IdentityNullCheckTest() - { - IIdentity identity = null; - Assert.Throws("identity", () => identity.GetUserId()); - Assert.Throws("identity", () => identity.GetUserName()); - ClaimsIdentity claimsIdentity = null; - Assert.Throws("identity", () => claimsIdentity.FindFirstValue(null)); - } - - [Fact] - public void IdentityNullIfNotClaimsIdentityTest() - { - IIdentity identity = new TestIdentity(); - Assert.Null(identity.GetUserId()); - Assert.Null(identity.GetUserName()); - } - - [Fact] - public void UserNameAndIdTest() - { - var id = CreateTestExternalIdentity(); - Assert.Equal("NameIdentifier", id.GetUserId()); - Assert.Equal("Name", id.GetUserName()); - } - - [Fact] - public void IdentityExtensionsFindFirstValueNullIfUnknownTest() - { - var id = CreateTestExternalIdentity(); - Assert.Null(id.FindFirstValue("bogus")); - } - - private static ClaimsIdentity CreateTestExternalIdentity() - { - return new ClaimsIdentity( - new[] - { - new Claim(ClaimTypes.NameIdentifier, "NameIdentifier", null, ExternalAuthenticationType), - new Claim(ClaimTypes.Name, "Name") - }, - ExternalAuthenticationType); - } - - private class TestIdentity : IIdentity - { - public string AuthenticationType - { - get { throw new NotImplementedException(); } - } - - public bool IsAuthenticated - { - get { throw new NotImplementedException(); } - } - - public string Name - { - get { throw new NotImplementedException(); } - } - } - } -} \ No newline at end of file