2

I am trying to setup development environment to integrate Google sign-in on Android using Web Authenticator in Xamarin Essentials.

  1. In the Web API project, same AuthController is included described in this article. It is running on https://localhost:44311/api

  2. To call the API from emulator, API url is referenced as https://10.0.2.2:43411/api as described in this article.

  3. Now, I am able to call the API url using await WebAuthenticator.AuthenticateAsync(apiUrl, callbackUrl)

  4. But, when API tries to invoke Google authentication via await Request.HttpContext.ChallengeAsync(scheme);, below error is returned from Google.

Error 400: invalid_request, device-id and device-name are required for the private IP: https://10.0.2.2:4311/signin-google

  1. As I understand, it is expecting request originated from the server instead of IP address like https://<servername>

  2. Whole situation comes down to be able to access the webservice using name (or localhost) to be used in both emulator and Google redirect uri.

Sunny
  • 4,765
  • 5
  • 37
  • 72
  • 2
    Google will not accept a local (private) IP address when doing Oauth calls.But here is a workaround, you can refer to it. https://stackoverflow.com/a/26021728/10627299 – Leon May 20 '20 at 07:34
  • I don't think it works when invoked from android device. In step 4, Request is executed using 10.0.2.2, AuthenticateAsync still shows the error. For it to work, hosts file should be ideally inside the android device. – Sunny May 20 '20 at 07:44
  • Yes, it will not work in Androd device as well. You should use public IP and certificated to replace of the local IP. – Leon May 21 '20 at 05:48
  • It is not possible to debug the API code by deploying to public IP. I have managed to work out a solution using nip.io which was one of the answers in workaround link. I will post the complete details later. – Sunny May 21 '20 at 12:32
  • Ok, waitting for your update. – Leon May 22 '20 at 07:29
  • @Sunny Could you post your solution as an answer please? – Brugner May 31 '20 at 17:47
  • @brunner, I am yet to understand how it is all working and am ocuppied untill 2 weeks. In a nutshell, I had used xip.io for the local api. Once this is configured, I started getting a error like authcookie is missing from within .net core. In the fiddler, I can see that response is received from Google and then, getting posted to .net core which is when it breaks. Next, I followed this article to https://learn.microsoft.com/en-us/aspnet/core/security/samesite?view=aspnetcore-3.1 and it worked. I didn't understand the flow completely but it enabled me to debug locally – Sunny Jun 01 '20 at 00:59

0 Answers0