Saturday 4 April 2020

MS Azure Tutorial | Login Using Microsoft Azure Active Directory And PHP...



Download Whole API with Composed Repository (Only for PHP v7.2 & Plus):- https://unpossiblepog.com/research-and-development/PHP/Magium-Active-Directory-With-VENDOR-For-Microsoft-Azure-SSO-Only-For-PHP-Version-7.2-And-Onward

Hey guys, this is UNPOSSIBLE POG.
In this video, I shall make a connection between microsoft azure and PHP, in short, an authentication using microsoft account through cloud service.
This service is one of the type of “Software as a service” that is SaaS.
As you know, microsoft Azure is a of the cloud-service provider where you can store your data, use it, execute it.
We are using AZURE to authenticate user’s account on their servers rather than our own server or computer.
What do I mean by that?
Suppose you have a website called www.xyz.com, than rather than creating your own login form, you can use microsoft’s login page. So what are the advantage?
Some of them are,
1, if you create your own login page, then it may have loopholes from where hackers can hack into your website. (Loophole maybe like sql injection, bruteforce login)
2, your code can validate email pattern but can not identify if they are real or not. For example if an intruder whats to access your service, then he can create add an email like random-person123@hammer.com which has same pattern as any email but may not exists in real world.
There are many more, but lets skip that for now.

There are 4 important requirements that you need to have.
1) Microsoft account (free trials / Purchased )
2) Should have a live website hosted on servers, with access of CPANEL, WHM or FTP (Filezilla)
3) Any SSL certificate should be installed on that domain. (HTTPS)
4) Linux Operating systems (Debian family) In your PC or LAPTOP with xampp installed in it (PHP version > 7 is recommended)

Lets get started.
Go to portal.azure.com
If you are using trial version, then click on “skip for now”
From top menu, click on “Azure active directory”
 Click on App registration.
Click on “New registration”
Type any random name that you want for application.
Make sure to select Multi tenant (tenant = users) with personal microsoft account.
Platform is optional.
Click on REGISTER.
Now scroll down,  and make select on “YES” on “Treat application as a public client”, and save it.
Then again, click on TOP MENU, “AZURE ACTIVE DIRECTORY”, then select the application we created.
Make sure to copy “APPLICATION (CLIENT) ID”, we need that later on.
Then click on “ADD a Redirect URI”.
You came back to same page of configuration.
Now click on “Add a platform”, and select “WEB”.
Now, I have one website with HTTPS enabled.
For now I shall use that link as redirect URL.
That UNPOSSIBLE_1 is just a folder that I am going to create later in my website, so don’t panic.
Make sure to tick “Access tokens” and “ID tokens”  checked, and click on configure.
You can also tick tokens configuration from here if you want to.
Now click on “Certificates and Secrets”,"New Client Secret”, add random description.
Click on “Add”.
Now make sure to copy this client for later use because next time when you come on same page, they won’t display you the secret value.
Lets again go to, top menu, Azure Active Directory, App registration, you can see that we have certificates ticked for our application.

Now lets jump to PHP.
I provided you the github link the the description.
Download ZIP,
Go to downloaded folder and paste it in HTDOCS folder of XAMPP.
I already downloaded it.
Extract it.
Now rename the extracted folder as the same name that we gave in the folder in my case its “UNPOSSIBLE_1”.
I am using sublime text for editor, but you can you anything like netbeans, notepad++ etc;
Notice that there is a folder called, “examples”, and inside it there is WWW, we are using this index.php as an executable program. So paste that path in redirect URL and save it.
In directories, go to HTDOCS and open your folder in terminal.
Now this is where things get tricky.

Open composer.json file inside your folder and copy those lines and paste it in require array of composer.json file.
Now here, type this.
In terminal type “sudo apt-get install composer” and enter your password.
I already installed composer.

Depending on your php version, type those commands, for CURL,
Sudo apt-get install php-curl
Oops, don’t forget to add SUDO before that command


Now run this command
“composer require, then name of library”
means “composer require  magium/active-directory”

You may see some problems like this, because there are many extension that may require for that JSON to run.
In simple words, currently we installed “php-curl”, which is one of the extension we needed.

You can paste those problems below in comment box, I shall try to find the solution to those problem. Most of the time, the problem could be the “mission extensions” in your system.
You can ignore this orange thing.
Now if you look inside program, there is a vendor folder which was generated by execute composer.json file.
Now we have to compress that file in ZIP only and upload it in LIVE WEBSITE using CPANEL, you can also you upload a whole folder via FTP, so that you don’t have to compress folder.(FTP takes more time to upload)
You will have to upload that zip file in public_html.
Once uploaded, go to file system, and extract that zip file.
Your folder will appear, now go inside that folder, then example, then the www.
Edit the index.php.
Add comma here.
HERE, have to add  new array key as ‘redirect_url’.
Add client ID, client secret, directory as common.

I made a mistake here, type “return_url” as a “key”.

Now, lets test it,  paste our link in browser’s URL.
You will be automatically redirected to Microsoft LOGIN.
Which means, that index.php file can be used as a login page for your web application.
You see that, they provide you some info about user, you can user’s email and name in PHP session  to maintain login and to create account.
Share it with your colleagues, friends, or employees to implement Microsoft azure authentication in your website.

Required links are given in the description.
Thanks for watching. 
Don’t forget to like, share and subscribe.
-------------------------------------------------------
Subscribe my Channel:-
http://www.youtube.com/user/SanketRooney?sub_confirmation=1

Facebook Page:-
https://www.facebook.com/UnpossibleNS

Twitter Account:-
https://twitter.com/UnpossiblePOG

Blog :-
https://unpossiblepog.blogspot.in/

No comments:

Post a Comment