Search code examples
asp.net.netasp.net-mvcgoogle-plus-signin

google sign in .net mvc default application


I am trying to add google sign in option in default .net mvc template project. As per many tutorials I tried to add the option but after redirecting to google sign in page and signing in it return backs to the default login page of the template as if nothing happened.

Things I've done so far to achieve this much,

.NET FRAMEWORK 4.5.2 copied the project url (SSL disabled) and pasted in redirect url with "/signin-google" attached. created Auth2.0 client Ids as per the image attached, pasted the ClientID and secret in app.UseGoogleAuthentication(new GoogleOAuth2AuthenticationOptions() { ClientId = "931587660641-s4smfbatgr1ufsq5u704qeigca22i8he.apps.googleusercontent.com", ClientSecret = "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" });

after attempting a few more times I've discovered the google sign prompt page actually sign in on thebrowser instead of the web app.

editor-screenshot Please help me find the solution and thanks in advance.


Solution

  • finally solved....!

    Did just one thing to achieve this.

    1. Set SSL Enabled Status = True.

    2. Right Click the Project ,Go to Properties.

    3. Copy the SSL URL in Project URL under WEB Tab and click on Create Virtual Directory Button next to it.

    4. Open Google API Credential and paste the URL under Authorized JavaScript origins like this https://localhost:48428

    5. Copy the same URL and Paste under 'Authorized redirect URIs' with /signin-google at the end, like this https://localhost:48428/signin-google

    6. Copy ClientID and Client Secret.

    7. Open Project , Go to Startup.Auth.cs under App_Start folder.

    8. Uncommand the below code and Paste the copied codes here

    app.UseGoogleAuthentication(new GoogleOAuth2AuthenticationOptions()
                {
                    ClientId = "",
                    ClientSecret = ""
                });
    
    
    1. Save and run your application and it should work.