And Authentication Using Facebook Oauth2.0: A Thesis Is Submitted To The Department of
And Authentication Using Facebook Oauth2.0: A Thesis Is Submitted To The Department of
Net MVC
and Authentication using Facebook Oauth2.0
Information Technology
Of
International Institute of Information Technology Bhubaneswar
in partial fulfilment of the requirements for the degree of
Bachelor of Technology
by
Shuvankar Pati
(Roll- B416047)
under the supervision of
Prof. Dr SriChandan Sobha Nayak
CSE
Shuvankar Pati
B416047
May 24, 2020
Certificate
This is to certify that the work in the thesis entitled Title of your Thesis by
Your Name is a record of an original research work carried out by him
under my supervision and guidance in partial fulfilment of the requirements
for the award of the degree of Bachelor of Technology in branch name.
Neither this thesis nor any part of it has been submitted for any degree or
academic award elsewhere.
MVC stands for Model, View, and Controller. MVC separates an application into
three components - Model, View, and Controller.
View: View in MVC is a user interface. View display model data to the user
and also enables them to modify them. View in ASP.NET MVC is HTML, CSS,
and some special syntax (Razor syntax) that makes it easy to communicate
with the model and the controller.
Controller: The controller handles the user request. Typically, the user uses
the view and raises an HTTP request, which will be handled by the controller.
The controller processes the request and returns the appropriate view as a
response.
The MVC framework handles converting the route data into a concrete controller that
can handle requests. After the controller has been created, the next major step
is Action Execution. A component called the action invoker finds and selects an
appropriate Action method to invoke the controller.
After our action result has been prepared, the next stage triggers, which is Result
Execution. MVC separates declaring the result from executing the result. If the result
is a view type, the View Engine will be called and it's responsible for finding and
rending our view.
If the result is not a view, the action result will execute on its own. This Result
Execution is what generates an actual response to the original HTTP request.
ViewBag,ViewData and TempData
ViewBag, ViewData, and TempData all are objects in ASP.NET MVC and these are
used to pass the data in various scenarios.
The following are the scenarios where we can use these objects.
ViewBag
ViewBag is a dynamic object to pass the data from Controller to View. And, this will
pass the data as a property of object ViewBag. And we have no need to typecast to
read the data or for null checking. The scope of ViewBag is permitted to the current
request and the value of ViewBag will become null while redirecting.
ViewData
ViewData is a dictionary object to pass the data from Controller to View where data is
passed in the form of key-value pair. And typecasting is required to read the data in
View if the data is complex and we need to ensure null check to avoid null exceptions.
The scope of ViewData is similar to ViewBag and it is restricted to the current request
and the value of ViewData will become null while redirecting.
TempData
TempData is a dictionary object to pass the data from one action to other action in the
same Controller or different Controllers. Usually, TempData object will be stored in a
session object. Tempdata is also required to typecast and for null checking before
reading data from it. TempData scope is limited to the next request and if we want
Tempdata to be available even further, we should use Keep and peek.
Controller Actions and Views
What is a Controller
In ASP.NET MVC, a Controller is used to define and group a set of actions.
An action (or action method) is a method on a controller that handles incoming
requests. Controllers provide a logical means of grouping similar actions together,
allowing common sets of rules (e.g. routing, caching, authorization) to be applied
collectively. Incoming requests are mapped to actions through routing.
In ASP.NET Core MVC, a controller can be any instantiable class that ends in
“Controller” or inherits from a class that ends with “Controller”. Controllers should follow
the Explicit Dependencies Principle and request any dependencies their actions require
through their constructor using dependency injections.
Defining Actions
Any public method on a controller type is an action. Parameters on actions are bound to
request data and validated using model binding.
Action methods should contain logic for mapping an incoming request to a business
concern. Business concerns should typically be represented as services that your
controller accesses through dependency injection. Actions then map the result of the
business action to an application state.
In ASP.NET Core MVC, views are .cshtml files that use the C# Language in Razor
markup.
Solution Explorer and N Layer Structure
The following is my Web app’s Solution explorer structure:
This is my Controller view in which account controller works for authentication
and user controller is for restaurant app purpose.
The corresponding views are:
As you can see the Web config file has all the essential database connection
strings and configuration settings.
Controller and their views
In this process I took help of online documentation and created an app using
facebook developers and deployed it in my web app.I was given a secret id and
secret authentication id for using it in my web app.I also used AllowAnnonymous
keyword data annotation for authorizing the web app based on the roles.
Account Controller
Now I will show you the process or control flow:
As you can see its already logged in. So I logged out and then redirected to
login page in facebook and then got authenticated.
Important Code Snippets
Conclusion and Further Implementation
The web application is working fine from end to end and was reviewed by my
training project camp lead.I was asked to use entity framework and implement
the same using web api and mvc by using jquery and ajax by consuming the web
api requests.This app can be used to facilitate the concept of online booking and
reserving hotel table,it was dynamically being updated based on adding billing
details and also displaying the no of persons left and the no of persons who are
still in the restaurant.It can further be improved by adding Menu,dishes,timing
etc.Iam working on it in this holiday break.
References
https://www.tutlane.com/tutorial/aspnet-mvc/oauth-facebook-login-for-asp-net-
mvc-website-with-example (for facebook auth)
https://docs.microsoft.com/en-us/aspnet/mvc/overview/security/create-an-
aspnet-mvc-5-app-with-facebook-and-google-oauth2-and-openid-sign-on
https://www.w3schools.com/bootstrap/bootstrap_modal.asp
(for bootstrap modals)