How to Secure Your Azure App Service With Twitter Authentication

Introduction

 
Please take a look at my previous articles about other types of authentication in Azure App Service which may help you to meet your application requirement.

Creating a Twitter Client App

 
Step 1
 
You need a Twitter account, to create a Twitter account go to twitter.com
 
Step 2
 
Go to Twitter for Developers and log in using your Twitter account
 
Step 3
 
Once logged in, from the top nav and select “Create an app” as below:
 
How To Secure Your Azure App Service With Twitter Authentication
 
Step 4
 
In the upcoming screen configure your app details like App Name, Description, Privacy Policy URL, App Logo.
 
It will also ask to fill website URL and Callback URL, fill it like below:
 
Website Url
 
https://<yourazureappname>.azurewebsites.net
 
Click the checkbox for “Enable Sign in with Twitter“
 
Callback URLs
 
https://<yourazureappname>.azurewebsites.net/.auth/login/twitter/callback
 
Note
Make sure you enter the above URL in lowercase format. This is because the website URL will be added as an authorized domain, it will be added as lowercase, and domain comparison will be done against the URL that we are adding now:
 
 
How To Secure Your Azure App Service With Twitter Authentication
 
Step 5
 
At the bottom of the page “Tell us how this app will be used” is a required field. Type at least 100 characters in this section. Click the “Create” button in the upcoming popup also click the “Create” button.
 
Step 6
 
In the upcoming dashboard section, go to the “Keys and tokens” tab and copy the API Key and API Secret Key. We will need this later to configure in the Azure App Service.
 
How To Secure Your Azure App Service With Twitter Authentication
 

Configuring Twitter Authentication in Azure App Service

 
Step 1
 
Login to Azure Portal, with enough permission to access the app service.
 
Step 2
 
Click on any of the app service applications on which you wish to enable Twitter authentication.
 
Step 3
 
In the upcoming properties pane look for Authentication/Authorization option like below. By default, Authentication is disabled, enable it using the toggler as you see in below screenshot.
 
How To Secure Your Azure App Service With Twitter Authentication
 
Step 4
 
In the upcoming screen select “Twitter” as the authentication type. Enter the App Key and API Secret you obtained from the Twitter developer account and click theOK button.
 
Step 5
 
Now, in the authentication screen, choose “Action to take when the request is not authenticated” as “Login with Twitter” and click Save.
 
How To Secure Your Azure App Service With Twitter Authentication
 
Step 6
 
Now that we are all set with the Twitter authentication, browse your application in the browser. You will be prompted to enter your Twitter credentials.
 
Once Twitter credentials are validated, you will get the below screen with the app information you configured in the Twitter developer account.
 
How To Secure Your Azure App Service With Twitter Authentication
 
Click “Authorize App”, which will take you to your actual Azure App Service application.
 
I hope this article helps you to enable Twitter authentication on an Azure App Service. If you have any questions/issues about this article, please let me know in the comments.