ASP.Net on Azure Apps cant redirect after Google login with new Users

Viewed 153

When using Google login authentication in ASP.Net 3.1 App that is deployed on Azure App Service the login isn't working properly for new users. We are using SQLite as a database while developing.

Website functions as intended when hosting locally and with the existing user in Database. When I try to log in with a new User via Google it shows the "select account" screen, after selecting a new Account the cookie for authentication is successfully created but the user is not created in the database it seems.

Chrome developer tools only show a (failed) on the Get request coming back from Google.
While Azure Insight shows a Google.Apis.Auth.OAuth2.LocalServerCodeReceiver.StartListener

I don't know how to troubleshoot this problem.
As mentioned above, login and functionality works as intended in development environment, and with the Google account that is saved in the database file already.
Creating new database entries for other functionalities works.

I suspect that the IActionResult GoogleResponse() is unable to create a new User in the database, but i don't know why or how to check.

So far I have tried:

  • adding the database file to the Azure App Server again C:\home\site\wwwroot\Database.
  • adding "websitename".azurewebsites.net to authorized domains in Google Cloud Platform
  • adding "https://"websitename".azurewebsites.net/signin-google" to Authorized redirect URIs
  • adding "https://"websitename".azurewebsites.net/.auth/login/google/callback" to Authorized redirect URIs
  • adding "https://"websitename".azurewebsites.net/login/google" to Authorized redirect URIs
  • adding ClientID and ClientSecret to Application Settings in Azure Apps Configuration
  • changing permissions to the database file via Kudu Debug console via ICACLS "C:\home\site\wwwroot\Database" /grant:r "users:(RX)" /C

Project Github Repo can be found here: https://github.com/MarioSchenkewitz/SWE-I-Gruppen-Finder-App/tree/master/
The Controller Action GoogleResponse() is in here: https://github.com/MarioSchenkewitz/SWE-I-Gruppen-Finder-App/blob/master/Speet/Controllers/AccountController.cs

EDIT
logging via cloudshell az webapp log tail --name appname --resource-group myResourceGroup gave me this exception stack:

[Error] Microsoft.AspNetCore.Diagnostics.ExceptionHandlerMiddleware: An unhandled exception has occurred while executing the request.
System.AggregateException: One or more errors occurred. (Access is denied.)
 ---> System.Net.HttpListenerException (5): Access is denied.
   at System.Net.HttpListener.SetupV2Config()
   at System.Net.HttpListener.Start()
   at Google.Apis.Auth.OAuth2.LocalServerCodeReceiver.StartListener()
   at Google.Apis.Auth.OAuth2.LocalServerCodeReceiver.ReceiveCodeAsync(AuthorizationCodeRequestUrl url, CancellationToken taskCancellationToken)
   at Google.Apis.Auth.OAuth2.AuthorizationCodeInstalledApp.AuthorizeAsync(String userId, CancellationToken taskCancellationToken)
   at Google.Apis.Auth.OAuth2.GoogleWebAuthorizationBroker.AuthorizeAsync(Initializer initializer, IEnumerable`1 scopes, String user, CancellationToken taskCancellationToken, IDataStore dataStore, ICodeReceiver codeReceiver)
   at Google.Apis.Auth.OAuth2.GoogleWebAuthorizationBroker.AuthorizeAsync(ClientSecrets clientSecrets, IEnumerable`1 scopes, String user, CancellationToken taskCancellationToken, IDataStore dataStore, ICodeReceiver codeReceiver)
   --- End of inner exception stack trace ---
   at System.Threading.Tasks.Task.ThrowIfExceptional(Boolean includeTaskCanceledExceptions)
   at System.Threading.Tasks.Task`1.GetResultCore(Boolean waitCompletionNotification)
   at System.Threading.Tasks.Task`1.get_Result()
   at Speet.Controllers.AccountController.GetGoogleProfile() in D:\a\SWE-I-Gruppen-Finder-App\SWE-I-Gruppen-Finder-App\Speet\Controllers\AccountController.cs:line 85
   at Speet.Controllers.AccountController.CreateUser(String userId) in D:\a\SWE-I-Gruppen-Finder-App\SWE-I-Gruppen-Finder-App\Speet\Controllers\AccountController.cs:line 61
   at Speet.Controllers.AccountController.GoogleResponse() in D:\a\SWE-I-Gruppen-Finder-App\SWE-I-Gruppen-Finder-App\Speet\Controllers\AccountController.cs:line 51
   at lambda_method(Closure , Object , Object[] )
   at Microsoft.Extensions.Internal.ObjectMethodExecutor.Execute(Object target, Object[] parameters)
   at Microsoft.AspNetCore.Mvc.Infrastructure.ActionMethodExecutor.SyncActionResultExecutor.Execute(IActionResultTypeMapper mapper, ObjectMethodExecutor executor, Object controller, Object[] arguments)
   at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.<InvokeActionMethodAsync>g__Logged|12_1(ControllerActionInvoker invoker)
   at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.<InvokeNextActionFilterAsync>g__Awaited|10_0(ControllerActionInvoker invoker, Task lastTask, State next, Scope scope, Object state, Boolean isCompleted)
   at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.Rethrow(ActionExecutedContextSealed context)
   at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.Next(State& next, Scope& scope, Object& state, Boolean& isCompleted)
   at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.InvokeInnerFilterAsync()
--- End of stack trace from previous location where exception was thrown ---
   at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.<InvokeNextResourceFilter>g__Awaited|24_0(ResourceInvoker invoker, Task lastTask, State next, Scope scope, Object state, Boolean isCompleted)
   at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.Rethrow(ResourceExecutedContextSealed context)
   at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.Next(State& next, Scope& scope, Object& state, Boolean& isCompleted)
   at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.InvokeFilterPipelineAsync()
--- End of stack trace from previous location where exception was thrown ---
   at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.<InvokeAsync>g__Logged|17_1(ResourceInvoker invoker)
   at Microsoft.AspNetCore.Routing.EndpointMiddleware.<Invoke>g__AwaitRequestTask|6_0(Endpoint endpoint, Task requestTask, ILogger logger)
   at Microsoft.AspNetCore.Authorization.AuthorizationMiddleware.Invoke(HttpContext context)
   at Microsoft.AspNetCore.Authentication.AuthenticationMiddleware.Invoke(HttpContext context)
   at Microsoft.AspNetCore.Diagnostics.ExceptionHandlerMiddleware.<Invoke>g__Awaited|6_0(ExceptionHandlerMiddleware middleware, HttpContext context, Task task)```
1 Answers

It seems the Problem was caused by the App using GoogleWebAuthorizationBroker.AuthorizeAsync to authorize (see this Stack overflow Answer)
Fixed the problem by following this guide, respective changes can be seen in the Repository in this commit, if anyone else encounters this problem

Related