我正在运行生成 JWT token 的 Go 服务器。我最初的计划是使用 http.Redirect 发送 token ,并使用 token 字符串作为 url 的一部分。
这似乎不起作用,因为我使用的是 Firebase 静态托管,因此只有客户端路由。
我如何推送我的代币?也许是标题?
- 我正在“example.firebaseapp.com”上运行我的静态 SPA (A)。
- 我正在运行在“example.us-west-2.compute.amazonaws.com”上生成 token 的服务器 (B)
- cas 服务器正在“https://login.example.edu/cas/”上运行' (C)
- 当然还有用户的计算机 (D)
流程如下
- 用户从静态主机加载网站 (A)
- 计算机 D 上的用户点击“通过学校登录”按钮并定向到我的服务器 (B)
- B 然后重定向到 cas 服务器 (C)。用户输入他的凭据并被重定向到计算机 B。
- 然后,计算机 B 使用 key 和 uid 生成 token 。
- 需要以某种方式将该 token 设置回用户
然后,用户将调用
ref.authWithCustomToken("AUTH_TOKEN", function(error, authData) {
Go 服务器代码
func (h *myHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
if !cas.IsAuthenticated(r) {
cas.RedirectToLogin(w, r)
return
}
if r.URL.Path == "/logout" {
cas.RedirectToLogout(w, r)
return
}
generatedToken := generateToken("uid") // token is created using a uid and a secret
redirectURL := websiteURL + generatedToken
println(redirectURL)
println(generatedToken)
http.Redirect(w, r, redirectURL, http.StatusFound) // I attempt to send the token using a redirect. This doesn't seem to work though since the static server only supports routing for '/'.
//html.WriteTo(w)
}
最佳答案
如果我正确理解了流程,那么您缺少的是应用程序用户与之对话并且可以将 token 返回给该用户的端点。
解决此问题的方法是让用户应用程序在步骤 2 中传递一个高度不可猜测的值(“请求 ID”),例如 UUID。然后, token 服务器可以在 /tokens/<requestID>
中的步骤 5 中将 token 写入 Firebase 数据库。 ,客户端正在监听它。
关于go - Firebase 自定义身份验证传递 token ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36106839/