namespace OAuthServiceProvider.Code { using System; using System.Collections.Generic; using System.Linq; using System.Security.Principal; using System.Web; /// /// Extension methods and other helpful utility methods. /// public static class Utilities { /// /// Gets the database entity representing the user identified by a given instance. /// /// The identity of the user. /// /// The database object for that user; or null if the user could not /// be found or if is null or represents an anonymous identity. /// public static User GetUser(this IIdentity identity) { if (identity == null || !identity.IsAuthenticated) { return null; } return Global.DataContext.Users.SingleOrDefault(user => user.OpenIDClaimedIdentifier == identity.Name); } } }