Related Documentation Download this Manual
PDF (US Ltr) - 5.5Mb
PDF (A4) - 5.5Mb
EPUB - 4.7Mb
HTML Download (TGZ) - 4.6Mb
HTML Download (Zip) - 4.6Mb


MySQL Connector/Net Developer Guide  /  ...  /  Adding OAuth Authentication to a Project

5.6.3 Adding OAuth Authentication to a Project

OAuth is another authentication option for websites that use the Simple Membership Provider. A user can be validated using an external account like Facebook, Twitter, Google, and others. The following steps enable authentication using a Google account in the application.

  • Go to the class AuthConfig.cs in the App_Start folder.

  • As we are using google, find the RegisterAuth method and uncomment the last line where it calls OauthWebSecurity.RegisterGoogleClient.

  • Run the application. Once the application is running, click Log in to open the log in page. Then, click Google under Use another service to log in.

    Figure 5.18 Simple Membership with OAuth: Google Service

    Simple Membership with OAuth: Google Service

  • This redirects to the Google login page (at google.com), and requests you to sign in with your Google account information.

    Figure 5.19 Simple Membership with OAuth: Google Service Login

    Simple Membership with OAuth: Google Service Login

  • After submitting the correct credentials, a message requests permission for your application to access the user's information. Read the description and then click Accept to allow the quoted actions, and to redirect back to your application's login page.

    Figure 5.20 Simple Membership with OAuth: Google Service Approval

    Simple Membership with OAuth: Google Service Approval

  • Now your application can register the account. The User name field will be filled in with the appropriate information (in this case, the email address that is associated with the Google account). Click Register to register the user with your application.

    Figure 5.21 Simple Membership with OAuth: Google Service Registration

    Simple Membership with OAuth: Google Service Registration

  • Now the new user is logged into the application from an external source using OAuth.

    Figure 5.22 Simple Membership with OAuth: Google Service Logged In

    Simple Membership with OAuth: Google Service Logged In

  • Information about the new user is stored in the UserProfile and Webpages_OauthMembership tables.

To use another external option to authenticate users, you must enable the client in the same class where we enabled the Google provider in this tutorial. Typically, providers require you to register your application before allowing OAuth authentication, and once registered they typically provide a token/key and an ID that must be used when registering the provider in the application.


User Comments
Sign Up Login You must be logged in to post a comment.