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.
CodePudding user response:
finally solved....!
Did just one thing to achieve this.
Set
SSL Enabled Status = True
.Right Click the
Project
,Go toProperties
.Copy the
SSL URL
in Project URL underWEB
Tab and click onCreate Virtual Directory
Button next to it.Open Google API Credential and paste the URL under
Authorized JavaScript origins
like thishttps://localhost:48428
Copy the same URL and Paste under 'Authorized redirect URIs' with
/signin-google
at the end, like thishttps://localhost:48428/signin-google
Copy
ClientID
andClient Secret
.Open Project , Go to
Startup.Auth.cs
underApp_Start
folder.Uncommand the below code and Paste the copied codes here
app.UseGoogleAuthentication(new GoogleOAuth2AuthenticationOptions()
{
ClientId = "",
ClientSecret = ""
});
- Save and run your application and it should work.