简体   繁体   English

Web 应用后端认证与交互

[英]Web application backend authentication and interaction

I'm currently writing a Web application backend in Go.我目前正在 Go 中编写 Web 应用程序后端。 What is the best way to make some kind of API available for a standard jQuery AJAX frontend to interact with my backend?使某种 API 可用于标准 jQuery AJAX 前端与我的后端交互的最佳方法是什么?

Right now, I have some functions that accept some data, perform operations, and return other data, but where exactly should I go from there?现在,我有一些函数可以接受一些数据、执行操作并返回其他数据,但是我应该从那里开始 go 呢? I have a vague idea of listening in on some port for a JSON-encoded function call and returning the JSON-encoded output of that function, but (if this is a good way of accomplishing this) what is the best way of accomplishing this? I have a vague idea of listening in on some port for a JSON-encoded function call and returning the JSON-encoded output of that function, but (if this is a good way of accomplishing this) what is the best way of accomplishing this?

Furthermore, how exactly should I handle a login system and/or authentication with Go/AJAX?此外,我应该如何使用 Go/AJAX 处理登录系统和/或身份验证? Would it make sense to return some unique hash key for that user, (save it to a cookie if persistent login is selected,) store that key in memory, and send that key as a parameter of every JSON-encoded function call sent to the server?为该用户返回一些唯一的 hash 密钥是否有意义(如果选择了持久登录,则将其保存到 cookie 中)将该密钥存储在 memory 中,并将该密钥作为每个 JSON 编码的 ZC1C425Z54074 调用的参数发送到发送的 C183945D1服务器? Or, is there a better way of accomplishing this (I'm not knowledgeable on login systems) or possibly a solution already developed for Go?或者,是否有更好的方法来实现这一点(我对登录系统不了解)或者可能已经为 Go 开发了解决方案?

Goajax is a JSON-RPC package for go. Goajax是用于 go 的 JSON-RPC package。 The style is somewhat you pass it function names and parameters via JSON, and it returns JSON as answer.风格有点像你通过 JSON 传递 function 名称和参数,它返回 JSON 作为答案。

Personally though, I prefer REST -services.不过就个人而言,我更喜欢REST服务。 REST uses standard web technologies, especially HTTP and URI for passing resources and what to do on them. REST 使用标准的 web 技术,特别是 HTTP 和 URI 用于传递资源以及对它们执行的操作。 JSON is very efficient for this as well. JSON 对此也非常有效。 For a REST-service, there is the rest.go library (also, a fork ).对于 REST 服务,有rest.go库(还有一个fork )。

For authentification, you may want to look at authcookie .对于身份验证,您可能需要查看authcookie "implements creation and verification of signed authentication cookies." “实现签名认证 cookies 的创建和验证。”

Using an auth-hash via cookie (or param as alternative) is a common way.通过 cookie(或作为替代的参数)使用 auth-hash 是一种常见的方式。 Make sure you are aware though, that you make them secure.确保你知道,你让他们安全。 Use HTTPS to prevent eavesdropping (WLANs, pub-nets, man-in-the-middles).使用 HTTPS 防止窃听(WLAN、pub-net、中间人)。 How you first validate them depends on what you're actually doing.您如何首先验证它们取决于您实际在做什么。 Also make sure to think about session lifetimes.还要确保考虑 session 的寿命。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM