public async Task EnrollSmsFactor() { var oktaClient = new OktaClient(); var guid = Guid.NewGuid(); // MFA Group w/ SMS policy var groupId = "{groupId}"; var createdUser = await oktaClient.Users.CreateUserAsync(new CreateUserWithPasswordOptions { Profile = new UserProfile { FirstName = "John", LastName = "Enroll-SMS", Email = $"john-enroll-sms-dotnet-authn-{guid}@example.com", Login = $"john-enroll-sms-dotnet-authn-{guid}@example.com", }, Password = "******", Activate = true, }); try { await oktaClient.Groups.AddUserToGroupAsync(groupId, createdUser.Id); var authnClient = TestAuthenticationClient.Create(); var authnOptions = new AuthenticateOptions() { Username = $"john-enroll-sms-dotnet-authn-{guid}@example.com", Password = "******", MultiOptionalFactorEnroll = true, WarnBeforePasswordExpired = true, }; var authnResponse = await authnClient.AuthenticateAsync(authnOptions); authnResponse.Should().NotBeNull(); authnResponse.Embedded.GetArrayProperty <Factor>("factors").Should().NotBeNull(); authnResponse.Embedded.GetArrayProperty <Factor>("factors").Should().HaveCountGreaterThan(0); authnResponse.AuthenticationStatus.Should().Be(AuthenticationStatus.MfaEnroll); var enrollOptions = new EnrollSmsFactorOptions() { PhoneNumber = "+1 415 555 5555", StateToken = authnResponse.StateToken, }; authnResponse = await authnClient.EnrollFactorAsync(enrollOptions); authnResponse.Should().NotBeNull(); authnResponse.AuthenticationStatus.Should().Be(AuthenticationStatus.MfaEnrollActivate); authnResponse.GetProperty <Factor>("factor").Should().NotBeNull(); authnResponse.GetProperty <Factor>("factor").Profile.GetProperty <string>("phoneNumber").Should().NotBeNullOrEmpty(); } finally { await createdUser.DeactivateAsync(); await createdUser.DeactivateOrDeleteAsync(); } }
public async Task <ActionResult> EnrollSmsAsync(EnrollSmsViewModel model) { if (!ModelState.IsValid) { return(View("EnrollSms", model)); } var enrollOptions = new EnrollSmsFactorOptions() { PhoneNumber = model.PhoneNumber, StateToken = Session["stateToken"].ToString(), }; try { var authnResponse = await _oktaAuthenticationClient.EnrollFactorAsync(enrollOptions).ConfigureAwait(false); if (authnResponse.AuthenticationStatus == AuthenticationStatus.MfaEnrollActivate) { Session["factorId"] = authnResponse.Embedded.GetProperty <Factor>("factor").Id; return(RedirectToAction("VerifyFactor", "Manage")); } throw new NotImplementedException($"Unhandled Authentication Status {authnResponse.AuthenticationStatus}"); } catch (Exception exception) { ModelState.AddModelError(string.Empty, exception.Message); return(View("EnrollSms", model)); } }
public async Task SendAsync(string phoneExtension, string phoneNumber) { var enrollOptions = new EnrollSmsFactorOptions() { StateToken = this.stateController.StateToken, PhoneExtension = phoneExtension, PhoneNumber = phoneNumber, FactorId = "mblry4uxieTrPiOcp0h7", Provider = this.Provider, }; var authResponse = await this.authnClient.EnrollFactorAsync(enrollOptions); this.stateController.ProcessAuthnResponse(authResponse); }