这可能看起来像一个愚蠢的问题,但我刚刚开始使用dart,需要验证用户使用$ _SESSION数组类似于你可以用PHP做的事情......
所以我正在编写一个基本的服务器后端和一个前端,需要通过XMLHttpRequest验证一些请求。后端根据给定前端是否经过身份验证发回JSON。在某些情况下,前端可以为经过身份验证的用户更新DOM,但仅。
不确定我是否正在解释这个......
任何建议都将不胜感激!!
谢谢!
答案 0 :(得分: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.');
}
答案 1 :(得分:0)
没有内置会话,但您可以查看最近使用oAuth的Google API库:
答案 2 :(得分:0)
JwtSessionHandler
实施提供了一个很好的全自动解决方案。
var authMiddleware = authenticate([new RandomAuthenticator()],
new JwtSessionHandler('super app', 'shhh secret', testLookup));