Gmail: OAuth
- Goto the link
- Login with your gmail username password
- Click on the google menu at the top left
- Click API Manager
- Click on Credentials
- Click Create Credentials and select OAuth Client
- Select Web Application as Application type and Enter the Name-> Enter Authorised Redirect URL (Eg: http://localhost:53922/signin-google) ->Click on Create button. This will create the credentials. Pls make a note of
Client ID
and Secret ID
. Finally click OK to close the credentials pop up.
- Next important step is to enable the
Google API
. Click on Overview in the left pane.
- Click on the
Google API
under Social APIs section.
- Click Enable.
That’s all from the Google part.
Come back to your application, open App_start/Startup.Auth.cs
and uncomment the following snippet
app.UseGoogleAuthentication(new GoogleOAuth2AuthenticationOptions()
{
ClientId = "",
ClientSecret = ""
});
Update the ClientId
and ClientSecret
with the values from Google API
credentials which you have created already.
- Run your application
- Click Login
- You will see the Google button under ‘Use Another Section to log in’ section
- Click on the Google button
- Application will prompt you to enter the username and password
- Enter the gmail username and password and click Sign In
- This will perform the OAuth and come back to your application and prompting you to register with the
Gmail
id.
- Click register to register the
Gmail
id into your application database.
- You will see the Identity details appear in the top as normal registration
- Try logout and login again thru Gmail. This will automatically logs you into the app.