/account-security-csharp

Two-Factor Authentication with ASP.NET Core and Authy

Primary LanguageC#

Twilio

Two-Factor Authentication with ASP.NET Core and Authy

Here you will learn how to create a login system for ASP.NET Core applications secured with 2FA using Authy.

Learn more about this code in our docs.

Quickstart

Create an Authy app

Enable Authy in your Twilio Account if you don't have one already, and then connect it to your Twilio account.

Local development

This project is built using Install .NET Core, which will need to be installed before continuing.

  1. First clone this repository and cd into it.

    git clone https://github.com/TwilioDevEd/account-security-csharp.git
    cd account-security-csharp 
  2. Install the dependencies.

    cd src/AccountSecurity
    dotnet restore 

MSSQL Server

You can either install it or run it in a docker container.

  • Install MSSQL Server Express

  • Run in a docker container:

    docker run -e 'ACCEPT_EULA=Y' -e 'SA_PASSWORD=yourStrong(!)Password' -p 1433:1433 --name mssql -d microsoft/mssql-server-linux:latest

  1. Make sure your DefaultConnection connection string is correct for your SQL Server installation. (You may need to change the Server to localhost\\SQLEXPRESS if running MSSQL Server Express on Windows.)

  2. Run the database migrations:

    dotnet ef database update -v
  3. Set your Authy App API Key in your appsettings.json as AuthyApiKey which should be found under your Authy App Settings.

  4. Run the server.

    dotnet run --environment development 
  5. Expose your application to the wider internet using ngrok. You can click here for more details. This step is important because the application won't work as expected if you run it through localhost.

    ngrok http 5000 

Once ngrok is running, open up your browser and go to your ngrok URL. It will look something like this: http://9a159ccf.ngrok.io

Meta

  • No warranty expressed or implied. Software is as is.
  • MIT License
  • Lovingly crafted by Twilio Developer Education.