Web API Xamarin Mobile 应用的身份验证

Web API Authentication for Xamarin Mobile app

目前正在开发 ASP.Net Core 6 API 以供 Xamarin 移动应用使用。

我只想知道两件事:

有什么想法吗?

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);
}
  • 我必须使用什么 ASP.Net Core Web API 身份验证? Jason Web Token (JWT) 或另一种适用于 Xamarin Mobile 的身份验证类型,如下图所示。

You could use JWT token without any hesitation its more used and secure authentication protocol now. Here is the example

  • 我如何保持 (JWT) cookie 身份验证有效并在结束后将其终止,然后将其在端点上传递给移动开发人员,以便他们可以使用它并从 Xamarin 应用程序中取消它,否则它将是自动完成

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

  • 如何将 JWT 令牌从 ASP.Net 核心 API 传递到 Xamarin 应用程序...因为 Web API 将从Xamarin 移动应用程序。 步骤是

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 this API from your Xamarin app taking user Id and password from User 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