Basics of Azure Active Directory with Android Studio Demonstration



What is Azure Active Directory?
Well before we answer what is Azure Active Directory we must first understand what the Domain Controller is.

Domain Controller(DC): is a server that manages network security, effectively acting as the gatekeeper for user authentication and authorisation. In simple terms its a log in system which you can implement within your Azure web or mobile app, to authenticate users sign in credentials and to then provide authorisation to get access to data in your application.

Authentication:  is the process of verifying oneself.
Authorisation:  Once authentication has been successful you are granted access to data in the application. Depending on your authorisation level you may only be able to access certain resources.

So what is Azure Active Directory?
is the central database on the domain controller where the login credentials(usernames and passwords) of all client computers, printers, and other shared resources in the network are stored. When someone tries to login, their login credentials must match those saved in Active Directory in order to gain access to the network resources(data in the application). Once you have signed in successfully, the Active directory provides you with a signed Access Token.

Access Token: This is a secure way to proof that the user has authorisation without having to pass usernames and passwords across the internet which is insecure. The information in a token includes the identity and privileges of the user account. An Access Token is a credential that can be used by an application to access an API, they inform the API that the bearer of the token has been authorised to access the API and perform specific actions specified by the scope/SQL Database that has been granted, this is Row Level Security. An API receiving this token would have a public key to decrypt the token.

Row-Level Security (RLS): simplifies the design and coding of security in your application. RLS helps you implement restrictions on data row access. For example is to restrict customers' data access to only the data relevant to their company.


Here is a Metaphor to bring everything above together:
Imagine you are trying to get into your office building but you have forgotten your pass so you go to the security guard aka the Domain Controller and ask to be authenticated. The security guards ask for your credentials such as your password and username, the security guard will then go on the computer and check if your credentials match what is on the database aka the Active Directory. If the credentials match, the security guard will give you a pass aka Access Token to show you have been authorised and you will be allowed in the building. Depending on your authorisation level you may only be able to access certain rooms. However if your credentials do no match whats on the database aka Active Directory, you will be denied access to the building. Anyway you have been authorised on this occasion so whilst inside the building you try to enter a room so you need to scan the pass aka Access Token to open the door, the scan will check if the pass aka Access Token is valid in the database aka the Active Directory and if successful it will then check the SQL database where all the application user data is stored to see if your pass aka Access Token has permission to enter this specific room aka Row Level Security, if yes then open the door, if no they then door stays closed.

Lets build an Android Application with Azure Active Directory!  

Add users to the Active Directory

Step 1: Create an account with Azure and go to the Azure dashboard
Step 2: Click on "Azure Active Directory"
Step 3: Click on "Custom Domain Names" and copy your domain name as you need it for the next step. It will look something like this: garethsanashee.onmicrosoft.com
Step 4: Click on "Users" then "New User" in the field "User Name" you must use your custom domain name from step 3. Once filled in click "Create" Here is what it will look like:



Create App Registration 

Step 5: Click "App Registrations" then click "New Registration" and give it a name and leave the check box "Accounts in this organisational directory only (Default Directory)" and press register.
Step 6: In the App Registration you just created click "Quick start" and Click on "Android" and follow the steps.

Key Point: Under "Generating a development Signature Hash. This will change for each development environment." copy the "keytool -exportcert -alias androiddebugkey..." paste into your CMD and press enter. This will either give you the keytool or tell you to install "OPENSSL". No password required just press enter!
How to get the Key Tool:
1. find where your key tool is on your computer, copy the path and paste in the "Environment Variables" > "System Path"
Example: c:\Program files\java\jre - 10.0.1\bin
if you can not find "java" file then you need to install Android Studio or the JVM from Oracle
2. Download "OPENSSL" then copy the path for this and paste in the "Environment Variables" > "System Path"
download from: https://slproweb.com/products/Win32OpenSSL.html

Step 7: Once you have created the Application in Azure, download and open the Android Studio project and copy and paste the code from the App registration instructions.
Step 8: Run the application on your device and this will give you an out the box log in application with the Graph API. You will find that you can only log into the app if you are part of the Azure Active Directory.

This is how it works:


Well done you have set up an Android Application with Azure Active Directory!


Comments

Popular posts from this blog

Basic Overview of Microsoft Azure?

Understanding the basics of REST API with HTTP and JSON

Android App - Gym League Table