Facebook Login Asp.net
Click Here >>> https://tinurll.com/2t7MKe
This is the next post in a series on authentication and authorisation in ASP.NET Core. In this post I look in moderate depth at the OAuth 2.0 protocol as it pertains to ASP.NET Core applications, walking through the protocol as seen by the user of your website as well as the application itself. Finally, I show how you can configure your application to use a Facebook social login when you are using ASP.NET Core Identity.
OAuth 2.0 is an open standard for authorisation. It is commonly used as a way for users to login to a particular website (say, catpics.com) using a third party account such as a Facebook or Google account, without having to provide catpics.com the password for their Facebook account.
When the user requests a page on your app that requires authorisation, they will be redirected to the login page. Here they can either login using a username and password to create an account directly with the site, or they can choose to login with an external provider - in this case just Facebook.
Following this link, the user is directed in their browser to their Facebook login page. Once they have logged in, or if they are already logged in, they must grant authorisation to our registered ASP.NET application to access the requested fields:
The description provided here omits a number of things such as handling expiration and refresh tokens, as well as the ASP.NET Core Identity process or associating the login to an email, but hopefully it provides an intermediate view of what is happening as part of a social login.
If you want to use a different external OAuth provider then you have several options. Microsoft provide a number of packages similar to the Facebook package shown which make integrating external logins simple. There are currently providers for Google, Twitter and (obviously) Microsoft accounts.
Here we will learn what is Oauth, and with this, we will see an example of how to implement the OAuth service provided by Facebook in ASP.NET MVC. Most web applications nowadays provide an Oauth login to access their application. Generally, Oauth is an open standard for authentication and authorization.
If we check any e-commerce portals, they have Google, Facebook, and Twitter buttons on the login page. If we click on the Facebook button, it will take us to the Facebook portal to login with our Facebook credentials. It will ask for access to public profile and EmailID information (Your public profile includes name, profile picture, age range, gender, language, country, and other public info). When we click on the okay button, we will register and automatically log in to the Ecommerce application.
In the above example, the client application will be (Flipkart, snapdeal, amazon, Jabong), and Oauth providers will be (Google, Facebook, Twitter, LinkedIn, Microsoft, and Yahoo). In asp.net mvc 4 have inbuilt features of Oauth. Now let's explorer Oauth step by step, starting from creating Application in asp.net mvc.
After running the application, you will see the Facebook button on the login page's right part. Now click on the Facebook button. It will take you to the Facebook login page here. You enter Facebook credentials and login to Facebook.
WARNING: There is a bug in the Facebook Javascript SDK that prevents you from performing logins when running on non-standard ports on localhost in Internet Explorer. You must either use port 80 or test this in a browser other than Internet Explorer.
In order to obtain an access token from your users you must present them with an authentication dialog. The method in which you present this dialog varies depending on which device your application is built for. Ultimately, regardless of the form factor you are presenting the user with a Facebook login web page.
In order to get an access token from your users on a website you must use the either the Facebook JavaScript SDK or perform what is called server flow authentication. In this tutorial we will use the Facebook JavaScript SDK to perform authentication. The Facebook JavaScript SDK will handle all the details of displaying the login dialog, requesting permissions, and parsing the authentication cookie for the access token.
ASP.NET Zero enables and configures social and external login providers in the PostInitialize method of {YourProjectName}WebHostModule.cs class. Some parts of social and externa login code is close sourced for licensing purposes in Abp.AspNetZeroCore and Abp.AspNetZeroCore.Web nuget packages.
You can find many documents on the web to learn how to obtain authentication keys for social platforms. So, we will not go to details of creating apps on social media platforms. Once you get your keys, you can writethem into appsettings.json. When you enable it, social media logos are automatically shown on the login page as shown below:
Just note that, social media logins and external logins are only available on Tenant scope. So, a tenant must be selected on the login page to see those logos, otherwise there will be no logos on the login page.
If you are using Azure AD for OpenID Connect and your app is multi-tenant on Azure side, then you need to disable issuer validation, so all Azure AD users can use your app. Note that, multi-tenant app here is the one you have created oSocial logins can be enabled and configured from server-side. Once they are properly configured, they are automatically shown in the user interface.
ASP.NET Zero allows to customize getting user's username, name and surname from claims when logging in via external login. By default there are two implementations of IExternalLoginInfoManager which are DefaultExternalLoginInfoManager and WsFederationExternalLoginInfoManager.
You can implement this class for any external login manager you want and return it the external login provider you want in ExternalLoginInfoManagerFactory.cs. After that, ASP.NET Zero will use your implementation to get username, name and surname when creating a local user record for the externally logged in user.
All the above sections are related to server side part of ASP.NET Zero. On Angular side social and external logins are handled in login/login.service.ts. Note that currently only Facebook, Google, OpenID Connect and ADFS authentications are implemented for Angular application. Microsoft and Twitter logins are on the road map.
When you click a social login or external login icon on the login page, there are two main flows. Facebook, Google and ADFS options opens a popup window and ask user to login. In that case, callback function for the selected provider will be called right away.
However, for OpenID Connect, clicking the icon will redirect you to external website and you will login on the external website. After that, you will be redirected back to ASP.NET Zero website (to login.component.ts). Then, the callback function for OpenID Connect will be called.
All callback functions makes a request to server-side app to validate the information gathered from external or social login provider. If the information is validated, a local user record will be created (only for the first time) and user will be logged in to ASP.NET Zero website.
So, Social login is a form of single sign-on using existing login information from an identity provider such as Facebook, Twitter, Google, or Microsoft to sign into a third-party website and using third party response create a new login account specifically for your website.
Here, in this window the user can fill in his / her account credentials and click on "Login", so, after clicking on the login button, Facebook is the authorized user and can return positive or negative feedback to our application.
So, in the above screen is the response that came from the Google + API. Here response contains user profile information with email and one unique id to identify the user. The rest of the other process is the same as Facebook so, convert response in JSON Object and invoke particular controller action method to further process the login request. The author has used simple coding and techniques to make you learn the process of authentication of FB/ Google+ in MVC development. This article is purposely intended for ASP.NET developers and the development community, indeed.
Authentication challenges are an extra measure invoked by the authorization system when unauthenticated users request access to a resource requiring authentication. For example, the IAuthenticationService may issue a challenge if an anonymous user clicks on a login link or requests access to a restricted resource. The authorization system uses a default authentication scheme (or a specified scheme if one exists) to invoke a challenge.
You can login with other account as well at same point of time. As, I have enabled the two authentication providers Twitter and Google, you are seeing both of these two at last section . And when I click on Google it takes me at Google login page. As soon as I put my credential and click on Sign in button. It shows me that I am logged in as using two accounts. Twitter and Google as
ASP.NET Core Identity is a membership system that enables you to add login functionality to your application, allowing visitors to create an account and login with a user name and password from Facebook, Google or other external login providers.
It helped me to view an Authorization Server as just another web application. It's an application where you can login with a username-password combination or with some other external provider. Up to this point, nothing is different from any other web applications we have build. 2b1af7f3a8