Hello everyone,
You can definitely use the same database and authentication system for both your ASP.NET MVC application and your Xamarin.Forms application. Here are some general steps you can follow to integrate authentication between the two:
- Expose an API endpoint from your ASP.NET MVC application that can authenticate users and return an access token. You can use ASP.NET Core Identity for this, which provides a simple way to manage user authentication and authorization.
- In your Xamarin.Forms application, create a login page where users can enter their credentials and authenticate with the API endpoint you created in step 1. You can use a library like Xamarin.Auth or IdentityModel.OidcClient to handle the authentication flow.
- Once the user is authenticated, store the access token securely in the Xamarin.Forms application. You can use the Xamarin.Essentials library to securely store the token in the device's keychain or secure storage.
- In any API requests you make from the Xamarin.Forms application, include the access token as an authorization header. Your ASP.NET MVC application can then use this token to authenticate and authorize the request.
You don't necessarily need to convert your ASP.NET Core application into a .NET Framework with Web API to follow this approach. Instead, you can simply expose your ASP.NET Core application's authentication endpoints via an API controller, and use that endpoint in your Xamarin.Forms application.
Overall, the approach you take will depend on the specifics of your application and what works best for your use case. But hopefully this gives you a general idea of how you can integrate authentication between your ASP.NET MVC and Xamarin.Forms applications.
This should work, if it does, let me know: