Ejemplo n.º 1
0
        public async Task<IdentityResult> AddExternalLogin(IPrincipal user, AddExternalLoginModel model, AuthenticationTicket ticket)
        {
            AuthenticationManager.SignOut(DefaultAuthenticationTypes.ExternalCookie);

            if (ticket == null || ticket.Identity == null || (ticket.Properties != null
                && ticket.Properties.ExpiresUtc.HasValue && ticket.Properties.ExpiresUtc.Value < DateTimeOffset.UtcNow))
            {
                return new IdentityResult("External login failure.");
            }

            var externalData = ExternalLoginData.FromIdentity(ticket.Identity);

            if (externalData == null) return new IdentityResult("The external login is already associated with an account.");

            return await UserManager.AddLoginAsync(user.Identity.GetUserId(), new UserLoginInfo(externalData.LoginProvider, externalData.ProviderKey));
        }
 public async Task<IHttpActionResult> AddExternalLogin(AddExternalLoginModel model)
 {
     return await RunTask(() => AccountManager.AddExternalLogin(User, model, AccessTokenFormat.Unprotect(model.ExternalAccessToken)));
 }