我正在使用带有 C# 后端的 Xamarin.Forms 重写我们的应用程序,并且我正在尝试在登录时使用 customauth。我已经让它工作到一定程度,但我正在努力将我想要从后端传递回 Xamarin 应用程序的一切。我正在获取令牌和用户 ID,但想要更多。
成功登录的后端代码似乎相对简单:
return Ok(GetLoginResult(body));
其中 GetLoginResult() 是:
private object GetLoginResult(IUser body)
{
var claims = new Claim[]
{
new Claim(JwtRegisteredClaimNames.Sub, body.username)
};
JwtSecurityToken token = AppServiceLoginHandler.CreateToken(
claims, signingKey, audience, issuer, TimeSpan.FromDays(30));
accounts account = db.accounts.Single(u => u.username.Equals(body.username));
return new LoginResult(account)
{
authenticationToken = token.RawData,
};
}
LoginResult 类是
public class LoginResult
{
public LoginResult(accounts account)
{
Response = 200;
CustomerId = account.CustomerId;
Modules = account.Modules;
User = new LoginResultUser
{
userId = account.id,
UserName = account.UserName,
EmployeeId = account.EmployeeId
};
}
[JsonProperty(PropertyName = "Response")]
public int Response { get; set; }
ETC
在应用程序中,我调用 customauth 如下:
MobileServiceUser azureUser = await _client.LoginAsync("custom", JObject.FromObject(account));
结果具有令牌和正确的用户 ID,但是如何使用后端传回的其他属性填充结果?我已经让后端工作并使用邮递员进行了测试,我得到的结果是我想要的,但我一直无法找到如何在应用程序中对其进行反序列化。