Exemplo n.º 1
0
        public async Task <IActionResult> Index(string returnUrl, CancellationToken cancellationToken)
        {
            if (string.IsNullOrWhiteSpace(returnUrl))
            {
                return(RedirectToAction("Index", "Errors", new { code = "invalid_request", ReturnUrl = $"{Request.Path}{Request.QueryString}", area = string.Empty }));
            }

            try
            {
                var query    = Unprotect(returnUrl).GetQueries().ToJObj();
                var clientId = query.GetClientIdFromAuthorizationRequest();
                var client   = await OAuthClientQueryRepository.FindOAuthClientById(clientId, cancellationToken);

                var loginHint = query.GetLoginHintFromAuthorizationRequest();
                return(View(new AuthenticateViewModel(returnUrl,
                                                      loginHint,
                                                      _translationHelper.Translate(client.ClientNames),
                                                      _translationHelper.Translate(client.LogoUris),
                                                      _translationHelper.Translate(client.TosUris),
                                                      _translationHelper.Translate(client.PolicyUris))));
            }
            catch (CryptographicException)
            {
                return(RedirectToAction("Index", "Errors", new { code = "invalid_request", ReturnUrl = $"{Request.Path}{Request.QueryString}", area = string.Empty }));
            }
        }
Exemplo n.º 2
0
        public async Task <IActionResult> Index(string returnUrl, CancellationToken cancellationToken)
        {
            if (string.IsNullOrWhiteSpace(returnUrl))
            {
                return(RedirectToAction("Index", "Errors", new { code = "invalid_request", ReturnUrl = $"{Request.Path}{Request.QueryString}", area = string.Empty }));
            }

            try
            {
                var schemes = await _authenticationSchemeProvider.GetAllSchemesAsync();

                var query    = Unprotect(returnUrl).GetQueries().ToJObj();
                var clientId = query.GetClientIdFromAuthorizationRequest();
                var client   = await OAuthClientQueryRepository.FindOAuthClientById(clientId, cancellationToken);

                var loginHint           = query.GetLoginHintFromAuthorizationRequest();
                var externalIdProviders = schemes.Where(s => !string.IsNullOrWhiteSpace(s.DisplayName));
                return(View(new AuthenticateViewModel(
                                loginHint,
                                returnUrl,
                                _translationHelper.Translate(client.ClientNames),
                                _translationHelper.Translate(client.LogoUris),
                                _translationHelper.Translate(client.TosUris),
                                _translationHelper.Translate(client.PolicyUris),
                                externalIdProviders.Select(e => new OpenID.UI.ViewModels.ExternalIdProvider
                {
                    AuthenticationScheme = e.Name,
                    DisplayName = e.DisplayName
                }).ToList())));
            }
            catch (CryptographicException)
            {
                return(RedirectToAction("Index", "Errors", new { code = "invalid_request", ReturnUrl = $"{Request.Path}{Request.QueryString}", area = string.Empty }));
            }
        }