public async Task BulkSendSponsorshipOfferAsync(string sponsoringOrgName, IEnumerable <OrganizationSponsorship> sponsorships) { var invites = new List <(string, bool, string)>(); foreach (var sponsorship in sponsorships) { var user = await _userRepository.GetByEmailAsync(sponsorship.OfferedToEmail); var isExistingAccount = user != null; invites.Add((sponsorship.OfferedToEmail, user != null, _tokenFactory.Protect(new OrganizationSponsorshipOfferTokenable(sponsorship)))); } await _mailService.BulkSendFamiliesForEnterpriseOfferEmailAsync(sponsoringOrgName, invites); }
public string GenerateCaptchaBypassToken(User user) => _tokenizer.Protect(new HCaptchaTokenable(user));
private async Task SendInviteAsync(EmergencyAccess emergencyAccess, string invitingUsersName) { var token = _dataProtectorTokenizer.Protect(new EmergencyAccessInviteTokenable(emergencyAccess, _globalSettings.OrganizationInviteExpirationHours)); await _mailService.SendEmergencyAccessInviteEmailAsync(emergencyAccess, invitingUsersName, token); }
public async Task <IActionResult> PreValidate(string domainHint) { try { // Validate domain_hint provided if (string.IsNullOrWhiteSpace(domainHint)) { return(InvalidJson("NoOrganizationIdentifierProvidedError")); } // Validate organization exists from domain_hint var organization = await _organizationRepository.GetByIdentifierAsync(domainHint); if (organization == null) { return(InvalidJson("OrganizationNotFoundByIdentifierError")); } if (!organization.UseSso) { return(InvalidJson("SsoNotAllowedForOrganizationError")); } // Validate SsoConfig exists and is Enabled var ssoConfig = await _ssoConfigRepository.GetByIdentifierAsync(domainHint); if (ssoConfig == null) { return(InvalidJson("SsoConfigurationNotFoundForOrganizationError")); } if (!ssoConfig.Enabled) { return(InvalidJson("SsoNotEnabledForOrganizationError")); } // Validate Authentication Scheme exists and is loaded (cache) var scheme = await _schemeProvider.GetSchemeAsync(organization.Id.ToString()); if (scheme == null || !(scheme is IDynamicAuthenticationScheme dynamicScheme)) { return(InvalidJson("NoSchemeOrHandlerForSsoConfigurationFoundError")); } // Run scheme validation try { await dynamicScheme.Validate(); } catch (Exception ex) { var translatedException = _i18nService.GetLocalizedHtmlString(ex.Message); var errorKey = "InvalidSchemeConfigurationError"; if (!translatedException.ResourceNotFound) { errorKey = ex.Message; } return(InvalidJson(errorKey, translatedException.ResourceNotFound ? ex : null)); } var tokenable = new SsoTokenable(organization, _globalSettings.Sso.SsoTokenLifetimeInSeconds); var token = _dataProtector.Protect(tokenable); return(new SsoPreValidateResponseModel(token)); } catch (Exception ex) { return(InvalidJson("PreValidationError", ex)); } }