コード例 #1
0
        public async Task <IActionResult> OnPostLinkLoginAsync(string provider)
        {
            // Clear the existing external cookie to ensure a clean login process
            await HttpContext.SignOutAsync(IdentityConstants.ExternalScheme);

            // Request a redirect to the external login provider to link a login for the current user
            var redirectUrl = Url.Page("./ExternalLogins", pageHandler: "LinkLoginCallback");
            var properties  = _signInManager.ConfigureExternalAuthenticationProperties(provider, redirectUrl, _userManager.GetUserId(User));

            return(new ChallengeResult(provider, properties));
        }
コード例 #2
0
        public IActionResult ExternalLogin(string provider, string returnUrl = null)
        {
            // Request a redirect to the external login provider.
            var redirectUrl = Url.Action(nameof(ExternalLoginCallback), "Account", new
            {
                returnUrl
            });
            var properties = _signInManager.ConfigureExternalAuthenticationProperties(provider, redirectUrl);

            return(Challenge(properties, provider));
        }
コード例 #3
0
        public async Task <IActionResult> LinkLogin(string provider)
        {
            // Clear the existing external cookie to ensure a clean login process
            await HttpContext.Authentication.SignOutAsync(_externalCookieScheme);

            // Request a redirect to the external login provider to link a login for the current user
            var redirectUrl = Url.Action(nameof(LinkLoginCallback), "Manage");
            var properties  = _signInManager.ConfigureExternalAuthenticationProperties(provider, redirectUrl, _userManager.GetUserId(User));

            return(Challenge(properties, provider));
        }
コード例 #4
0
        public IActionResult OnPost(string provider, string returnUrl = null)
        {
            // Request a redirect to the external login provider.
            var redirectUrl = Url.Page("./ExternalLogin", pageHandler: "Callback", values: new { returnUrl });

            _logger.LogInformation($"redirectUrl {redirectUrl}.");
            redirectUrl = redirectUrl.Replace("http", "https");
            _logger.LogInformation($"redirectUrl Atualizado{redirectUrl}.");
            var properties = _signInManager.ConfigureExternalAuthenticationProperties(provider, redirectUrl);

            return(new ChallengeResult(provider, properties));
        }
コード例 #5
0
        public async Task <IActionResult> LinkLogin(string provider)
        {
            ViewData["AlleCategorien"] = _categorieRepository.GetAll().ToList();
            // Clear the existing external cookie to ensure a clean login process
            await HttpContext.SignOutAsync(IdentityConstants.ExternalScheme);

            // Request a redirect to the external login provider to link a login for the current user
            var redirectUrl = Url.Action(nameof(LinkLoginCallback));
            var properties  = _signInManager.ConfigureExternalAuthenticationProperties(provider, redirectUrl, _userManager.GetUserId(User));

            return(new ChallengeResult(provider, properties));
        }
コード例 #6
0
 public IActionResult SignInWithExternalProvider(string provider, string returnUrl)
 {
     string callback = Url.Action(
         nameof(HandleExternalLogin),
         new { returnUrl });
     
     var authenticationProperties = _signInManager.ConfigureExternalAuthenticationProperties(
         provider,
         callback);
     
     return Challenge(authenticationProperties, provider);
 }
コード例 #7
0
        public async Task <IActionResult> ExternalLoginAsync(string provider, string returnUrl = null)
        {
            if (_signInManager.IsSignedIn(User))
            {
                await HttpContext.SignOutAsync(IdentityConstants.ExternalScheme); // Clear the existing external cookie to ensure a clean login process
            }
            // Request a redirect to the external login provider.
            var redirectUrl = Url.Action(nameof(ExternalLoginCallback), "Account", new { returnUrl });
            var properties  = _signInManager.ConfigureExternalAuthenticationProperties(provider, redirectUrl, _userManager.GetUserId(User));

            return(new ChallengeResult(provider, properties));
        }
コード例 #8
0
        public IActionResult ExternalLogin(string provider, string returnUrl = null)
        {
            if (Request.Cookies["Identity.External"] != null)
            {
                Response.Cookies.Delete("Identity.External");
            }

            // Request a redirect to the external login provider.
            var redirectUrl = Url.Action("ExternalLoginCallback", "Account", new { ReturnUrl = returnUrl });
            var properties = _signInManager.ConfigureExternalAuthenticationProperties(provider, redirectUrl);
            return Challenge(properties, provider);
        }
コード例 #9
0
        public IActionResult ExternalLogin(string returnUrl, string authType)
        {
            if (Request.Cookies["Identity.External"] != null)
            {
                Response.Cookies.Delete("Identity.External");
            }
            string redirectUrl = Url.Action("ExternalResponse", "Account", new { returnUrl = returnUrl });

            AuthenticationProperties properties = _signInManager.ConfigureExternalAuthenticationProperties(authType, redirectUrl);

            return(new ChallengeResult(authType, properties));
        }
コード例 #10
0
        public async Task <ChallengeResult> Handle(LinkLogin request, CancellationToken cancellationToken)
        {
            // Clear the existing external cookie to ensure a clean login process
            await _httpContextAccessor.HttpContext.SignOutAsync(IdentityConstants.ExternalScheme);

            // Request a redirect to the external login provider to link a login for the current user
            var redirectUrl = _appUrlBuilder.Build(ClientRoutes.LinkLogin);

            var properties = _signInManager.ConfigureExternalAuthenticationProperties(request.Provider, redirectUrl, _userManager.GetUserId(request.User));

            return(new ChallengeResult(request.Provider, properties));
        }
コード例 #11
0
        public IActionResult ExternalLogin(string provider, string returnUrl = null)
        {
            LoggerController.AddBeginMethodLog(this.GetType().Name, MethodBase.GetCurrentMethod().Name);
            s.Restart();
            // Request a redirect to the external login provider.
            var redirectUrl = Url.Action(nameof(ExternalLoginCallback), "Account", new { returnUrl });
            var properties  = _signInManager.ConfigureExternalAuthenticationProperties(provider, redirectUrl);

            s.Stop();
            LoggerController.AddEndMethodLog(this.GetType().Name,
                                             MethodBase.GetCurrentMethod().Name, s.ElapsedMilliseconds);
            return(Challenge(properties, provider));
        }
コード例 #12
0
        public virtual async Task <IActionResult> OnPostExternalLogin(string provider)
        {
            if (_accountOptions.WindowsAuthenticationSchemeName == provider)
            {
                return(await ProcessWindowsLoginAsync());
            }

            var redirectUrl = Url.Page("./Login", pageHandler: "ExternalLoginCallback", values: new { ReturnUrl, ReturnUrlHash });
            var properties  = SignInManager.ConfigureExternalAuthenticationProperties(provider, redirectUrl);

            properties.Items["scheme"] = provider;

            return(Challenge(properties, provider));
        }
コード例 #13
0
        public IActionResult Login(
            string provider,
            string returnUrl = DefaultRedirect)
        {
            string redirectUrl = Url.Action(
                nameof(ExternalLoginCallback),
                "auth",
                new { Provider = provider, ReturnUrl = returnUrl });

            AuthenticationProperties properties = _signInManager
                                                  .ConfigureExternalAuthenticationProperties(provider, redirectUrl);

            return(new ChallengeResult(provider, properties));
        }
コード例 #14
0
        public IActionResult ExternalLogin(string provider, string returnUrl)
        {
            var redirectUrl = Url.Action("ExternalLoginCallback", "Account", new { returnUrl = returnUrl });
            var properties  = signInManager.ConfigureExternalAuthenticationProperties(provider, redirectUrl);

            try
            {
                return(new ChallengeResult(provider, properties));
            }
            catch (System.Exception)
            {
                return(View("Login"));
            }
        }
コード例 #15
0
        public ActionResult ExternalLogin(string provider, string returnUrl, string ss = "")
        {
            var redirectUrl = Url.Action(
                "ExternalLoginCallback",
                "Account",
                new
            {
                ReturnUrl  = returnUrl,
                authSchema = provider,
                ss         = ss
            });

            var properties = _signInManager.ConfigureExternalAuthenticationProperties(provider, redirectUrl);

            return(Challenge(properties, provider));
        }
コード例 #16
0
        public IActionResult FacebookExplicitLogin(string provider, string returnUrl = null)
        {
            switch (provider.ToLower())
            {
            case "facebook":
                var redirectUrl = Url.Action(nameof(ExternalLoginCallBack), "token", new { returnUrl });
                var properties  = SignInManager.ConfigureExternalAuthenticationProperties(provider, redirectUrl);
                return(Challenge(properties, provider));

            default:
                return(BadRequest(new
                {
                    Error = String.Format($"Provider:{provider} is not supported.")
                }));
            }
        }
コード例 #17
0
        public async Task <IActionResult> ExternalLoginAsync(string provider, string returnUrl = null)
        {
            //await HttpContext.SignOutAsync(IdentityConstants.ExternalScheme);
            ////var authProperties = new AuthenticationProperties
            ////{
            ////    RedirectUri = Url.Action(nameof(ExternalLoginCallback), "Profile", new { returnUrl= Url.Action("Index", "Home") })
            ////};
            //var properties2 = SignInManager.ConfigureExternalAuthenticationProperties(provider, Url.Action("Index", "Home"));
            //return Challenge(properties2, "Facebook");
            await HttpContext.SignOutAsync(IdentityConstants.ExternalScheme);

            var redirectUrl = Url.Action(nameof(ExternalLoginCallback), "Profile", new { returnUrl });
            var properties  = SignInManager.ConfigureExternalAuthenticationProperties(provider, redirectUrl);

            return(Challenge(properties, provider));
        }
コード例 #18
0
        public IActionResult ExternalLogin(string provider, string returnUrl = null)
        {
            switch (provider.ToLower())
            {
            case "facebook":
            case "google":
            case "twitter":
                // Request a redirect to the external login provider.
                var redirectUrl = Url.Action("ExternalLoginCallback", "Accounts", new { ReturnUrl = returnUrl });
                var properties  = SignInManager.ConfigureExternalAuthenticationProperties(provider, redirectUrl);
                return(Challenge(properties, provider));

            default:
                return(BadRequest(new { Error = String.Format("Provider '{0}' is not supported.", provider) }));
            }
        }
コード例 #19
0
 //[ValidateAntiForgeryToken]
 public IActionResult ExternalIdentityLogin([FromBody] LoginModel loginModel)
 {
     if (ModelState.IsValid)
     {
         if (loginModel.IdentityProvider == "Microsoft" || loginModel.IdentityProvider == "Google")
         {
             string redirectUrl = Url.Action("ExternalIdentityProviderResponse", "Account", new { loginModel.ReturnUrl });
             var    properties  = signInManager.ConfigureExternalAuthenticationProperties(loginModel.IdentityProvider, redirectUrl);
             return(new ChallengeResult(loginModel.IdentityProvider, properties));
         }
         else
         {
             throw new System.InvalidOperationException("External Identity Provider is not configured");
         }
     }
     return(BadRequest());
 }
コード例 #20
0
        public async Task <IActionResult> OnGetAsync(string returnUrl = null)
        {
            returnUrl = returnUrl ?? "/Identity/Account/Login";


            Response.SetCookie(LoginWellKnown.LoginReturnUrlCookieName, returnUrl, 360);
            if (!_agentTracker.IsLoggedIn)
            {
                var dd = $"/Identity/Account/Login?returnUrl={WebUtility.UrlEncode(returnUrl)}";
                return(Redirect($"/Identity/Account/ExternalAgentLogins?returnUrl={WebUtility.UrlEncode(dd)}"));
            }



            var context = await _interaction.GetAuthorizationContextAsync(returnUrl);

            if (context != null)
            {
                var idpProvider = (from item in context.AcrValues
                                   where item.StartsWith("idp=")
                                   select item.Substring(4)).FirstOrDefault();
                if (!string.IsNullOrEmpty(idpProvider))
                {
                    var redirectUrl = Url.Page("./ExternalLogin", pageHandler: "Callback", values: new { returnUrl });
                    var properties  = _signInManager.ConfigureExternalAuthenticationProperties(
                        idpProvider, redirectUrl);
                    return(new ChallengeResult(idpProvider, properties));
                }
            }

            if (!string.IsNullOrEmpty(ErrorMessage))
            {
                ModelState.AddModelError(string.Empty, ErrorMessage);
            }

            returnUrl = returnUrl ?? Url.Content("~/");

            // Clear the existing external cookie to ensure a clean login process
            await HttpContext.SignOutAsync(IdentityConstants.ExternalScheme);

            ExternalLogins = (await _signInManager.GetExternalAuthenticationSchemesAsync()).ToList();

            ReturnUrl = returnUrl;
            return(Page());
        }
コード例 #21
0
        public async Task <IActionResult> ExternalLogin([FromBody] LoginViewModel model)
        {
            var schemes = await _signInManager.GetExternalAuthenticationSchemesAsync();

            var provider = schemes.SingleOrDefault(a => a.DisplayName == model.AuthProvider);

            if (provider == null)
            {
                _logger.LogWarning(LogEvent.EXTERNAL_PROVIDER_NOTFOUND, "Could not find provider {PROVIDER}.", model.AuthProvider);
                return(BadRequest(_errorLocalizer[ErrorMessages.AuthProviderError]));
            }
            // Request a redirect to the external login provider.
            var redirectUrl = Url.Action(
                action: nameof(ExternalLoginCallback),
                controller: "Account",
                values: new { RememberUser = model.RememberUser });
            var properties = _signInManager.ConfigureExternalAuthenticationProperties(provider.Name, redirectUrl);

            return(Challenge(properties, provider.Name));
        }
コード例 #22
0
        public ActionResult LinkExternalLogin([FromQuery] string provider, [FromQuery] string redirectUrl)
        {
            var UserID = GetUserIdFromSession();

            if (string.IsNullOrWhiteSpace(UserID))
            {
                throw new Exception("no user sign in");
            }

            HttpContext.SignOutAsync(IdentityConstants.ExternalScheme).Wait();

            var RedirectUri = Url.Action("LinkExternalLoginCallback");

            var properties = _SignInManager.ConfigureExternalAuthenticationProperties(provider, RedirectUri, UserId.ToString());

            properties.Items.Add("redirectUrl", redirectUrl);
            properties.Items.Add("userId", UserID);
            properties.Items.Add("scheme", provider);

            return(Challenge(properties, provider));
        }
コード例 #23
0
 public IActionResult ExternalLogin(string provider, string returnUrl = null)
 {
     try
     {
         // Request a redirect to the external login provider.
         var redirectUrl = Url.Action(nameof(ExternalLoginCallback), "Account", new { ReturnUrl = returnUrl });
         var properties  = _signInManager.ConfigureExternalAuthenticationProperties(provider, redirectUrl);
         return(Challenge(properties, provider));
     }
     catch (Exception ex)
     {
         log = new EventLog()
         {
             EventId = (int)LoggingEvents.USER_LOGIN, LogLevel = LogLevel.Error.ToString(), Message = ex.Message, StackTrace = ex.StackTrace, Source = ex.Source
         };
         _loggerService.SaveEventLogAsync(log);
         return(RedirectToAction("Error", "Error500", new ErrorViewModel()
         {
             Error = ex.Message
         }));
     }
 }
コード例 #24
0
        public IActionResult OnPost(string provider, string returnUrl = null)
        {
            bool isLoggedIn = false;
            bool isAdmin    = false;

            var currentUser = this.User;

            if (currentUser.Identity.IsAuthenticated)
            {
                isLoggedIn = true;
                isAdmin    = currentUser.Claims.Any(c => c.Value == "Admin");
            }

            ViewData["LoggedIn"] = isLoggedIn.ToString();
            ViewData["IsAdmin"]  = isAdmin.ToString();

            // Request a redirect to the external login provider.
            var redirectUrl = Url.Page("./ExternalLogin", pageHandler: "Callback", values: new { returnUrl });
            var properties  = _signInManager.ConfigureExternalAuthenticationProperties(provider, redirectUrl);

            return(new ChallengeResult(provider, properties));
        }
コード例 #25
0
        public async Task <IActionResult> ExternalLogin(string provider, string returnUrl = null)
        {
            // Kiểm tra yêu cầu dịch vụ provider tồn tại
            var listprovider     = (await _signManager.GetExternalAuthenticationSchemesAsync()).ToList();
            var provider_process = listprovider.Find((m) => m.Name == provider);

            if (provider_process == null)
            {
                return(NotFound("Dịch vụ không chính xác: " + provider));
            }

            // redirectUrl - là Url sẽ chuyển hướng đến - sau khi CallbackPath (/dang-nhap-tu-google) thi hành xong
            // nó bằng /account/externallogin?handler=Callback
            // tức là gọi CallbackAsync
            string redirectUrl = Url.Action(nameof(ExternalLoginConfirmation), new { ReturnUrl = returnUrl });

            // Cấu hình
            var properties = _signManager.ConfigureExternalAuthenticationProperties(provider, redirectUrl);

            // Chuyển hướng đến dịch vụ ngoài (Googe, Facebook)
            return(Challenge(properties, provider));
        }
コード例 #26
0
ファイル: AccountController.cs プロジェクト: agsyazilim/Ags
        public IActionResult ExternalLogin(string provider, string returnUrl = null)
        {
            // Request a redirect to the external login provider.
            string redirectUrl = Url.Action("ExternalLoginCallback", "Account", new { ReturnUrl = returnUrl });

            Microsoft.AspNetCore.Authentication.AuthenticationProperties properties = _signInManager.ConfigureExternalAuthenticationProperties(provider, redirectUrl);
            return(Challenge(properties, provider));
        }
コード例 #27
0
 public IActionResult ExternalLogin(string provider, string returnUrl)
 {
     var redirectUrl = Url.Action("ExternalLoginCallback", "Account", new { ReturnUrl = returnUrl });
     var properties = _signInManager.ConfigureExternalAuthenticationProperties(provider, redirectUrl);
     return new ChallengeResult(provider, properties); //after returning it will take us to google sign in page and if signin is successfull we go to callback function
 }
コード例 #28
0
 public async Task <AuthenticationProperties> GetExternalAuthenticationProperties(string provider, string redirectUrl)
 {
     return(await Task.FromResult(_signInManager.ConfigureExternalAuthenticationProperties(provider, redirectUrl)));
 }
コード例 #29
0
 public AuthenticationProperties ConfigureExternalAuthenticationProperties(string provider, string redirectUrl, string userId)
 {
     return(_signInManager.ConfigureExternalAuthenticationProperties(provider, redirectUrl, userId));
 }
コード例 #30
0
        public IActionResult Login(string provider, string returnUrl)
        {
            var properties = _signInManager.ConfigureExternalAuthenticationProperties(provider, "/api/accounts/ExternalLoginCallback?returnurl=" + returnUrl);

            return(new ChallengeResult(provider, properties));
        }