Click here to Skip to main content
15,888,199 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
i am facing this problem and trying from last many days ,, i am using .net core 3.0 with google auth i have set up evertying and working fine until call back method (return uri) where i get this error invalid or missing state...

What I have tried:

public IActionResult ExternalLogin(string provider, string returnUrl)
       {
           // provider = "Google";
           //Issue a challenge to external login middleware to trigger sign in process
           //return new ChallengeResult(provider);

           //var RedirectUri = "https://localhost:5001/Account/Externallogincallback";
           var RedirectUri = Url.Action("Externallogincallback", "Account",
            new { ReturnUri = returnUrl },"https");
           string userId = null;
           var properties = _signInManager.ConfigureExternalAuthenticationProperties(provider, RedirectUri,userId);
           //options.StateDataFormat.Protect(properties)
           return new ChallengeResult(provider, properties);
       }



startup.cs

services.AddSession();
            services.AddAuthentication()

         .AddGoogle(options =>
         {


             IConfigurationSection googleAuthNSection = Configuration.GetSection("Authentication:Google");

             options.SignInScheme = IdentityServerConstants.ExternalCookieAuthenticationScheme;
             options.ClientId = "968526748268-4qo60g0g10bnvm1i0l8hllo7dcdg4l8j.apps.googleusercontent.com";
             options.ClientSecret = "1B8awSbGR5jboG9oG4OmWrat";

             options.ClaimsIssuer = "https://www.googleapis.com/oauth2/v1/certs";
             //options.CallbackPath = "https://localhost:5001/Account/Externallogincallback";
             options.CallbackPath = new PathString("/Account/Externallogincallback");

           
             options.AuthorizationEndpoint = "https://accounts.google.com/o/oauth2/auth";
             options.TokenEndpoint = "https://oauth2.googleapis.com/token";
             //options.UserInformationEndpoint = "https://api.googleusercontent.com/user";
             options.UserInformationEndpoint = "https://www.googleapis.com/oauth2/v2/userinfo";
             options.SaveTokens = true;
             options.Scope.Add("https://www.googleapis.com/auth/user.birthday.read");
             options.ClaimActions.MapJsonKey("urn:google:picture", "picture", "url");
             options.ClaimActions.MapJsonKey("urn:google:locale", "locale", "string");
             options.SaveTokens = true;
Posted
Updated 12-Nov-19 16:16pm
v2

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