I have used the ASP.NET Core React project template to create a web application into which I've installed Identity Server 4. The React app takes care of all the user interaction, with the dotnet application used as an API only. I've integrated a Google OAuth2 authentication option using the services.AddAuthentication().AddGoogle
builder extension provided by Microsoft.AspNetCore.Authentication
. Finally, the whole thing is containerised and deployed to a Linux App Service on Azure.
Most of my code was ported from a previous version which was a very similar setup but in that case I'd added a custom React app to an existing ASP.NET application rather than start with the official React project template for dotnet. Back then everything worked well. But I'm facing problems with my new version when deployed to Azure. Here's a Fiddler trace to highlight the issue:
vault2
is a client of the identity service. identity-azure
is the Identity Server application. The flow this trace shows is as follows:
- User clicks Sign In on the Vault application
- Browser is redirected to the Identity application
- User clicks the Google button to initiate the OAuth2 flow
- User signs in with Google account
- User is redirected to the default callback URL (
https://identity-azure.<domain>.com/signin-google?state=...
)
This last step is where the problem is. You'll notice that you don't see the callback URL in the Fiddler trace, but instead you see a couple of other requests (e.g. service-worker.js
) which are clearly being made from the React app. So the signin-google
path is being handled by the browser's cached React app and not the server. The React app uses react-router-redux
to handle certain routes client-side, and of course signin-google
is not one of these so it appears to be returning an empty component.
As far as I can tell, all my ASP.NET routes (implemented using the Route
attribute to decorate controller action methods) are handled consistently by the server. However, the signin-google
route is implemented in the authentication middleware so as far as I know I don't have much control over it other than to change its path. Is there something I can do to force this to be handled server-side?
I should add that this behaviour is quite erratic. It seems that if my Google account is signed out then the above is observed, but if my account is already signed in then signin-google
returns the expected 302 status code and the OAuth2 flow continues successfully.