Click here to Skip to main content
15,899,026 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
There's a problem. I do not understand . I couldn't solve a problem.
I want to login with google. Github and Msdn could not help me = (
I love your community. I hope I get the answer to my question as soon as possible.

Thanks for help

What I have tried:

I have reviewed and applied the links here but I could not reach the result

One

Two

Three

Four
Posted
Updated 23-Sep-19 18:04pm

Use Google's Login In MVC Application is easy, you don't need to write more code to achieve it. Follow Below Steps for reach the result:

1. First, Open Visual Studio, Create new ASP.NET MVC Application with individual user authentication.

2. Now go to solution explorer in your project, Right click on to your project and select properties, select Web from the menus and take note of the  Project URL, as you will need this when specifying the Redirect URI in Google.

3. Now create a new project in the Google Developers Portal in order to use Google as an external authentication provider in your website, you will need to create a project in the Google Developers Console. Head on over to the Google Developers Console. Make sure you must have to login with Google account. Firstly, click on to Create project button.

4. In the New Project dialog, give a name to your project and ID. 

ID would be default auto created after giving name of project. Click on to Create button to create your project.

5. Now you can see project name.
Next, you need to click on  Google +API.

6. Click on to Enable button, by clicking on to enable button API will be enabled.

7. You must have to enter your credentials, by which you can use API in your project.
So click on to  Create Credentials and under it choose OAuth client ID.

8. For OAuth consent screen, click on Configure consent screen to it.

9. In the OAuth consent screen panel, enter your email_id and product name which have been registered yet, click on to save button to save this.

10. Now click on create credentials and you have shown OAuth client id option, And then click on client id.

11. Click on radio button i.e. web application and click on to create button.

12. Now enter your URL in authorized redirect URLs

You mention your correct URL as on project in Visual Studio, go to properties of your existing project and copy URL from there.

13. Then click on create on click button.

14. After click on create button, the client ID and client secret will be generated. Now copy both client id and client secret form here.

15. Now go to project, In Solution Explorer, APP_START folder would be there. In APP_START folder you have STARTUP.AUTH.CS class, just click on to that class.

16. After clicking on that class, scroll down the page and you just show app.usegoogleAuthentication(), where you need to enter your client ID and client secret. 

Below this you have a client id and client secret. Paste that client id and client secret

17. Now run your application. Press F5 to run it. you can see the Login option at top right of your MVC application's Home page. 

Note: we created here a default MVC app so login option will be at top right of your MVC application's Home page. 

18. Now, Login with your Google account for authenticate. Click on Google to Login. After clicking on button, you will be redirected to Google's website. Where you will see google's Sign-in page.

19. After Login, Google will then prompt you to give the application permissions to access your personal data.

So, This is the simple and easy way to Login with Google account in your MVC application. I hope you enjoyed this solution.Thank you
 
Share this answer
 
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900