The AddPhoneNumber action method displays a dialog box to enter a phone number that can receive SMS messages. Clicking on the Phone Number : remove link passes Message=RemovePhoneSuccess as a query string. Clicking on your user ID (email) in the title bar doesn't pass a message. The Index method also displays the state or your 2FA phone number, external logins, 2FA enabled, and remember 2FA method for this browser(explained later). The Index action method in Manage controller sets the status message based on your previous action and provides links to change your local password or add a local account. Logins = await UserManager.GetLoginsAsync(()),īrowserRemembered = await AuthenticationManager.TwoFactorBrowserRememberedAsync(()) TwoFactor = await UserManager.GetTwoFactorEnabledAsync(()), PhoneNumber = await UserManager.GetPhoneNumberAsync(()), : message = ManageMessageId.RemovePhoneSuccess ? "Your phone number was removed." : message = ManageMessageId.AddPhoneSuccess ? "The phone number was added." : message = ManageMessageId.Error ? "An error has occurred." : message = ManageMessageId.SetTwoFactorSuccess ? "Your two factor provider has been set." : message = ManageMessageId.SetPasswordSuccess ? "Your password has been set." Message = ManageMessageId.ChangePasswordSuccess ? "Your password has been changed." Public async Task Index(ManageMessageId? message) The Manage view shows your phone number was added. In a few seconds you will get a text message with the verification code. Run the app and log in with the account you previously registered.Ĭlick on your User ID, which activates the Index action method in Manage controller. var soapSms = new 2SoapClient("ASPSMSX2Soap") Twilio doesn't currently have an async API, so return success. Trace.TraceInformation(result.Status) Status is one of Queued, Sending, Sent, Failed or null if the number is not valid Public Task SendAsync(IdentityMessage message) Implementation of data transfer to SMS providerĬonfigure the SmsService class in the App_Start\Identit圜onfig.cs file.ĭepending on the used SMS provider activate either the Twilio or the ASPSMS section: public class SmsService : IIdentityMessageService See Jon Atten's ASP.NET MVC: Keep Private Settings Out of Source Control. The account and credentials are added to the code above to keep the sample simple. Security - Never store sensitive data in your source code. Public static string SMSAccountFrom = "+15555551234" Public static string SMSAccountPassword = "My Password" Public static string SMSAccountIdentification = "My Idenfitication" Make the credentials and sender phone number available to the app: public static class Keys Transferring SMS provider credentials into app We will later store this value in the variable SMSAccountFrom. Within the Unlock Originators Menu, unlock one or more Originators or choose an alphanumeric Originator (Not supported by all networks). įrom the Numbers tab, copy your Twilio phone number. We will later store these values in the variables SMSAccountIdentification and SMSAccountPassword. The following service reference needs to be added:įiguring out SMS Provider User credentialsįrom the Dashboard tab of your Twilio account, copy the Account SID and Auth token.įrom your account settings, navigate to Userkey and copy it together with your self-defined Password. In the Package Manager Console, enter the following command: Install-Package Twilio Installing additional packages or adding service references This tutorial provides instructions for using either Twilio or ASPSMS but you can use any other SMS provider.Ĭreating a User Account with an SMS provider Warning: If you change any of the security settings in this sample, productions apps will need to undergo a security audit that explicitly calls out the changes made. Alternatively, you can keep the ViewBag.Status display to test how this app works locally without having to hook up and send email and SMS messages. Optional: Remove the ViewBag.Status code from the Manage and Account controllers and from the Views\Account\Verif圜ode.cshtml and Views\Manage\VerifyPhoneNumber.cshtml razor views. See the DisplayEmail and ForgotPasswordConfirmation action methods and razor views ). Optional: Remove the demo email link confirmation code from the sample (The ViewBag.Link code in the account controller. Optional: Follow the instructions in my Email confirmation tutorial to hook up SendGrid and then run the app and register an email account. The Identity.Samples package installs the code we will be working with. In this tutorial, we'll use SendGrid to send email and Twilio or ASPSMS for sms texting. Install-Package SendGrid Install-Package -Prerelease In the Package Manager Console, enter the following the following commands: Warning: You must install Visual Studio 2013 Update 2 to complete this tutorial.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |