duanchuli5647 2016-03-19 20:36
浏览 203
已采纳

Firebase自定义身份验证传递令牌

I am running a Go server that generates JWT tokens. My original plan was to send the tokens using an http.Redirect using the token string as part of the url.

This doesn't appear to work because I'm using Firebase static hosting and hence only have client side routing.

How can I push my token? Headers maybe?

  • I'm running my static SPA on 'example.firebaseapp.com' (A).
  • I'm running my server that generates tokens on 'example.us-west-2.compute.amazonaws.com' (B)
  • The cas server is running on 'https://login.example.edu/cas/' (C)
  • There is also of course the user's computer (D)

The flow goes as follows

  1. User load website from static host (A)
  2. User on computer D clicks 'login through school' button and is directed to my server (B)
  3. B then redirects to cas server (C). User puts in his credentials and is redirected to computer B.
  4. Computer B then generates a token using a secret key and a uid.
  5. This token needs to somehow be set back to the user User would then call ref.authWithCustomToken("AUTH_TOKEN", function(error, authData) {

Go Server Code

    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)

    }
  • 写回答

1条回答

  • duandie0884 2016-03-20 00:17
    关注

    If I understand the flow correctly, then what you're missing is an end point that your app user talks to and that can return the token to that user.

    A workaround for this would be to have the user app pass in a highly unguessable value (a "request ID") in step 2, something like a UUID. The token server can then write the token into the Firebase Database in step 5 in /tokens/<requestID>, where the client is listening for it.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 安卓adb backup备份应用数据失败
  • ¥15 eclipse运行项目时遇到的问题
  • ¥15 关于#c##的问题:最近需要用CAT工具Trados进行一些开发
  • ¥15 南大pa1 小游戏没有界面,并且报了如下错误,尝试过换显卡驱动,但是好像不行
  • ¥15 没有证书,nginx怎么反向代理到只能接受https的公网网站
  • ¥50 成都蓉城足球俱乐部小程序抢票
  • ¥15 yolov7训练自己的数据集
  • ¥15 esp8266与51单片机连接问题(标签-单片机|关键词-串口)(相关搜索:51单片机|单片机|测试代码)
  • ¥15 电力市场出清matlab yalmip kkt 双层优化问题
  • ¥30 ros小车路径规划实现不了,如何解决?(操作系统-ubuntu)