public UserAuthenticationOptions(ICoreUserContext userContext, PathString tokenEndpointPath, TimeSpan accessTokenExpireTimeSpan, TimeSpan refreshTokenExpireTimeSpan, bool allowInsecureHttp = true)
        {
            UserContext                = userContext;
            TokenEndpointPath          = tokenEndpointPath;
            AccessTokenExpireTimeSpan  = accessTokenExpireTimeSpan;
            RefreshTokenExpireTimeSpan = refreshTokenExpireTimeSpan;
            AllowInsecureHttp          = allowInsecureHttp;

            PasswordValidator = new Microsoft.AspNet.Identity.PasswordValidator();
        }
示例#2
0
        /// <summary>
        /// This creates an instance of CoreUserManager
        /// </summary>
        /// <param name="userContext">An implementation of the BasicAuthentication.Users.UserContext abstract class. </param>
        /// <param name="provider">An instance of a Microsoft.AspNet.IdentityIUserTokenProvider &lt; TUser, string &gt; class which is used to provide password reset tokens.</param>
        /// <example>
        /// An Microsoft.AspNet.IdentityIUserTokenProvider &lt; TUser string &gt; can be created using a Microsoft.Owin.Security.DataProtection.IDataProtectionProvider as follows:
        /// <code>
        /// Microsoft.Owin.Security.DataProtection.IDataProtectionProvider provider; This needs to be created, here for reference.
        /// var tokenProvider = new Microsoft.AspNet.Identity.Owin.DataProtectorTokenProvider&lt;BasicAuthentication.Users.IdentityUser&gt;(provider.Create("EmailConfirmation"));
        /// </code>
        /// </example>
        public CoreUserManager(ICoreUserContext userContext, IUserTokenProvider <ICoreIdentityUser, string> provider)
            : base(new UserStore <ICoreIdentityUser>(userContext))
        {
            this.UserContext       = userContext;
            this.UserTokenProvider = provider;

            this.UserValidator = new UserValidator <ICoreIdentityUser>(this)
            {
                AllowOnlyAlphanumericUserNames = false,
            };
        }
示例#3
0
        public static async Task <ICoreIdentityUser> GetLoggedInUserAsync(ICoreUserContext userContext)
        {
            IIdentity userIdentity = null;

            if (HttpContext.Current != null && HttpContext.Current.User != null)
            {
                userIdentity = HttpContext.Current.User.Identity;
            }
            if (userIdentity == null)
            {
                return(null);
            }
            var user = await userContext.FindUserByNameAsync(userIdentity.Name);

            return(user);
        }
示例#4
0
        /// <summary>
        /// This creates an instance of CoreUserManager
        /// </summary>
        /// <param name="userContext">An implementation of the BasicAuthentication.Users.UserContext abstract class. </param>
        /// <param name="provider">A Microsoft.Owin.Security.DataProtection.IDataProtectionProvider instance used to create a Microsoft.AspNet.IdentityIUserTokenProvider &lt; TUser, string &gt;.</param>
        /// <example>
        /// A Microsoft.Owin.Security.DataProtection.IDataProtectionProvider can be created inside an OWIN startup class as follows:
        /// <code>app.GetDataProtectionProvider();</code>
        /// </example>
        public CoreUserManager(ICoreUserContext userContext, IDataProtectionProvider provider)
            : base(new UserStore <ICoreIdentityUser>(userContext))
        {
            this.UserContext = userContext;

            //TODO:
            // token provider and user manager needs to be static i think:
            // https://stackoverflow.com/questions/25405307/asp-net-identity-2-giving-invalid-token-error

            var tokenProvider = new DataProtectorTokenProvider <ICoreIdentityUser>(provider.Create("EmailConfirmation", "ResetPassword"))
            {
                TokenLifespan = TimeSpan.FromDays(7)
            };

            this.UserTokenProvider = tokenProvider;

            this.UserValidator = new UserValidator <ICoreIdentityUser>(this)
            {
                AllowOnlyAlphanumericUserNames = false,
            };
        }
示例#5
0
        public static ICoreIdentityUser GetLoggedInUser(ICoreUserContext userContext)
        {
            IIdentity userIdentity = null;

            if (HttpContext.Current != null && HttpContext.Current.User != null)
            {
                userIdentity = HttpContext.Current.User.Identity;
            }
            if (userIdentity == null)
            {
                return(null);
            }
            var result = userContext.FindUserByNameAsync(userIdentity.Name);

            result.Wait();
            if (result.Status != TaskStatus.RanToCompletion)
            {
                throw new Exception("Enable to complete async task in non-async mode:\n" + result.Status);
            }
            return(result.Result);
        }
示例#6
0
 public UserStore(ICoreUserContext userContext)
 {
     UserContext = userContext;
 }
示例#7
0
 public static ICoreIdentityUser GetLoggedInUser(this ApiController controller, ICoreUserContext userContext)
 {
     return(GetLoggedInUser(controller.RequestContext, userContext));
 }
示例#8
0
 public static async Task <ICoreIdentityUser> GetLoggedInUserAsync(this ApiController controller, ICoreUserContext userContext)
 {
     return(await GetLoggedInUserAsync(controller.RequestContext, userContext));
 }
示例#9
0
        public static ICoreIdentityUser GetLoggedInUser(HttpRequestContext requestContext, ICoreUserContext userContext)
        {
            var user = requestContext.Principal.Identity;
            //var result = CoreAuthenticationEngine.UserManager.FindByNameAsync(user.Name);
            var result = userContext.FindUserByNameAsync(user.Name);

            result.Wait();
            if (result.Status != TaskStatus.RanToCompletion)
            {
                throw new Exception("Enable to complete async task in non-async mode:\n" + result.Status);
            }
            return(result.Result);
        }
示例#10
0
        public static async Task <ICoreIdentityUser> GetLoggedInUserAsync(HttpRequestContext requestContext, ICoreUserContext userContext)
        {
            var user   = requestContext.Principal.Identity;
            var result = await userContext.FindUserByNameAsync(user.Name);

            return(result);
        }
示例#11
0
 protected MakePaymentService(IUnitOfWork unitOfWork, ICoreUserContext userContext)
 {
     _unitOfWork  = unitOfWork;
     _userContext = userContext;
 }
示例#12
0
 public MobileRechargeService(IUnitOfWork unitOfWork, ICoreUserContext userContext)
     : base(unitOfWork, userContext)
 {
     _unitOfWork  = unitOfWork;
     _userContext = userContext;
 }
示例#13
0
 public UserService(IUnitOfWork unitOfWork, ICoreUserContext userContext)
 {
     _unitOfWork  = unitOfWork;
     _userContext = userContext;
 }
 public ElectricityService(IUnitOfWork unitOfWork, ICoreUserContext userContext)
     : base(unitOfWork, userContext)
 {
     _unitOfWork  = unitOfWork;
     _userContext = userContext;
 }