Currently developing an ASP.Net Core 6 API to be consumed from a Xamarin mobile app.
I just want to know two things :
What ASP.Net Core Web API authentication must I use? Jason Web Token (JWT) or another type of authentication suitable for Xamarin Mobile as per below image.
How do I keep (JWT) cookies authentication alive and kill it after then pass it on endpoint through to the mobile developer so they can use it and cancel it from the Xamarin app or it will be done automatically ?
How do I pass the JWT token from the ASP.Net Core API to the Xamarin App... because the Web API will be consumed from an Xamarin Mobile App.
Any idea please ?
private static async Task ProcessRepositories()
{
client.DefaultRequestHeaders.Accept.Clear();
client.DefaultRequestHeaders.Accept.Add(
new MediaTypeWithQualityHeaderValue("application/vnd.test.v3 json"));
client.DefaultRequestHeaders.Add("User-Agent", "crmsystem Repository Reporter");
var stringTask = client.GetStringAsync("https://api.crm.com/data/repo");
var msg = await stringTask;
Console.Write(msg);
}
CodePudding user response:
- What ASP.Net Core Web API authentication must I use? Jason Web Token (JWT) or another type of authentication suitable for Xamarin Mobile as per below image.
You could use JWT token without any hesitation its more used and secure authentication protocol now. Here is the example
- How do I keep (JWT) cookies authentication alive and kill it after then pass it on endpoint through to the mobile developer so they can use it and cancel it from the Xamarin app or it will be done automatically
Regarding
cookie authentication
you could set token life time there. After that particular time token would be expire automatically. You could have a look here in official document
- How do I pass the JWT token from the ASP.Net Core API to the Xamarin App... because the Web API will be consumed from an Xamarin Mobile App. Steps are
Step:1 Login/Authentication controller:
Your API should have Authentication controller which is check user login attempt and generate token. you can read more on official document
Step:2 Request Login API for getting token:
You have to call thisAPI
from yourXamarin app
takinguser Id
andpassword
fromUser login Form
which it return you the token. Here is the sample code
Step:3 Pass Bearer Token to Access Data:
Finally, use token for any kind of request to API. You can have look on our official docs here