0

enter image description hereI am trying to use google authentication in .net core but its giving me error - The oauth state was missing or invalid.

Please suggest what i am doing wrong

amethianil
  • 480
  • 2
  • 7
  • 16
  • Give more information about when the problem occurs and eventually some code along with it. – Samuil Petrov Apr 25 '17 at 11:56
  • Please see my setting for app startup- http://stackoverflow.com/questions/43607514/google-authentication-exception-no-authentication-handler-is-configured-to-hand – amethianil Apr 25 '17 at 12:00
  • app.UseCookieAuthentication(new CookieAuthenticationOptions { LoginPath = new PathString("/account/login"), AuthenticationScheme = "MyCookieMiddlewareInstance", AccessDeniedPath = new PathString("/Home/AccessDenied"), }); app.UseGoogleAuthentication(new GoogleOptions { AuthenticationScheme = "Google", DisplayName = "Google", SignInScheme = "Cookies", ClientId = "ClientId ", ClientSecret = "ClientSecret ", }); – amethianil Apr 25 '17 at 12:06

2 Answers2

0
//For google client....
using (var stream = new FileStream("client_secrets.json", FileMode.Open, FileAccess.Read))
        {
            credential = await GoogleWebAuthorizationBroker.AuthorizeAsync(
                GoogleClientSecrets.Load(stream).Secrets,
                new[] { BooksService.Scope.Books },
                "user", CancellationToken.None, new FileDataStore("Books.ListMyLibrary"));
        }

// Create the service.
        var service = new BooksService(new BaseClientService.Initializer()
            {
                HttpClientInitializer = credential,
                ApplicationName = "Books API Sample",
            });
  var bookshelves = await service.Mylibrary.Bookshelves.List().ExecuteAsync();
        ...
    }

 Thats the example of how you can create google client and service to make google authentication 
  • If you have any problem #amethianil.. comment me – Hariom Bhardwaj Apr 25 '17 at 12:49
  • I have created Google authentication part please check here my startup.cs class setting- http://stackoverflow.com/questions/43607514/google-authentication-exception-no-authentication-handler-is-configured-to-hand When its redirecting from google then its showing this error-The oauth state was missing or invalid I have implemented its in .net working fine but in .net core not working – amethianil Apr 25 '17 at 13:10
0

Maybe, the problem is that you incorretly set the googleOptions.CallbackPath. Try this answer. It helped me. https://stackoverflow.com/a/61950614/9547346

osynavets
  • 1,199
  • 1
  • 12
  • 22