Example #1
0
        public static bool IsExternalLoginOnly(this LoginInfoDto dto)
        {
            if (dto == null)
            {
                throw new ArgumentNullException(nameof(dto));
            }

            return(dto.EnableLocalLogin == false && dto.ExternalProviders?.Count() == 1);
        }
Example #2
0
        public static string ExternalLoginScheme(this LoginInfoDto dto)
        {
            if (dto == null)
            {
                throw new ArgumentNullException(nameof(dto));
            }

            return(dto.IsExternalLoginOnly() ? dto.ExternalProviders?.SingleOrDefault()?.AuthenticationScheme : null);
        }
        public async Task <IActionResult> Login(string returnUrl)
        {
            // build a model so we know what to show on the login page
            LoginInfoDto dto = await this.BuildLoginInfoDtoAsync(returnUrl);

            if (dto.IsExternalLoginOnly())
            {
                // we only have one option for logging in and it's an external provider
                return(await this.ExternalLogin(dto.ExternalLoginScheme(), returnUrl));
            }

            return(Ok(dto));
        }