Xamarin.Forms会话管理 [英] Xamarin.Forms Session Management

查看:208
本文介绍了Xamarin.Forms会话管理的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用Xamarin.Forms开发一个虚拟应用程序,我主要关注UWP. 我有此应用程序的登录功能,我需要管理会话.我正在使用一种基本的Web服务登录方法,它获取用户名和密码作为参数并返回访问令牌.我正在将此访问令牌用于此应用程序的CRUD操作.这就是我存储此访问令牌的方式.

I am trying to develop a dummy app with Xamarin.Forms and i mainly focus on UWP. I have a login feature for this app and i need to manage sessions. I am consuming a basic web service method for login, it gets user name and password as parameters and returns an access token. I am using this access token for the CRUD operations of this app. This is how i store this access token.

Application.Current.Properties ["access_token"] = token.access_token;

由于我是Xamarin的新手,因此我很难理解会话管理.我要如何管理会议?何时终止会话,如何进行?安全问题可能是什么?我如何正确注销用户?

Since i am a newbie for Xamarin i am struggling to understand Session Managament. How am i going to manage a session ? When to expire a session and how ? What might be the security issues ? How can i properly log out a user ?

任何帮助将不胜感激.

推荐答案

您可以使用用于Xamarin和Windows的设置插件.

此插件将特定属性直接保存到每个平台的本机设置API(NSUserDefaults,SharedPreferences等).这样可以确保每个应用程序以最快,最安全,最可靠的方式创建和编辑设置.此外,它还可以与任何Xamarin应用程序一起使用,而不仅限于Xamarin.Forms.

This plugin saves specific properties directly to each platforms native settings APIs (NSUserDefaults, SharedPreferences, etc). This ensures the fastest, most secure, and reliable creation and editing settings per application. Additionally, it works with any Xamarin application, not just Xamarin.Forms.

在以下网址的Nuget中使用它:-用于Xamarin和Windows 3.0.1的设置插件

Use it from Nuget at - Settings Plugin for Xamarin and Windows 3.0.1

此处找到文档.

private static ISettings AppSettings =>
    CrossSettings.Current;

public static string AccessToken
{
  get => AppSettings.GetValueOrDefault(nameof(AccessToken), string.Empty); 
  set => AppSettings.AddOrUpdateValue(nameof(AccessToken), value); 
}

会话是在服务器而不是客户端上管理的.您将从服务器获取到期时间,也许还会获得刷新令牌URL.您可以使令牌过期并在过期时间过后将其删除.

Sessions are managed at servers and not clients. You will get a expiration time and maybe a refresh token URL from the server. You can expire the token and delete it when the expiration time is elapsed.

这篇关于Xamarin.Forms会话管理的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆