3

这似乎是一个愚蠢的问题,但我刚刚开始使用 dart,需要验证用户会话,类似于使用 $_SESSION 数组对 PHP 执行的操作......

所以我正在编写一个基本的服务器后端和一个前端,并且需要对通过 XMLHttpRequest 进来的一些请求进行身份验证。后端根据给定的前端是否经过身份验证发回 JSON。在某些情况下,前端可以更新 DOM,但仅限于经过身份验证的用户。

不知道我是否解释得很好......

任何意见,将不胜感激!!

谢谢!

4

3 回答 3

2

会话是不应该成为任何语言的一部分的高级功能。您可以通过实施类似的东西自己包含会话功能。

  Map<String, int> sessions = {'abcdef12345' : 42}; // exists in e.g. datastore and is managed by an authentication routine 

  String authenticationToken = 'abcdef12345'; // comes from the request
  if(sessions.containsKey(authenticationToken)) {
    print('User ${sessions[authenticationToken]} is at least authenticated but might not have the appropriate rights to perform this operation.');
  } else {
    print('Not authenticated.');
  }
于 2012-08-08T17:09:43.973 回答
0

没有内置会话,但您可以查看最近的 Google API 库,以便 Dart 使用 oAuth:

谷歌 API Dart 客户端

于 2012-08-08T17:10:07.297 回答
0

shelf_auth为会话处理提供了一个很好的全自动解决方案,它的JwtSessionHandler实现

var authMiddleware = authenticate([new RandomAuthenticator()],
      new JwtSessionHandler('super app', 'shhh secret', testLookup));
于 2014-10-06T14:36:24.190 回答