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 矩阵加法的规则是两个矩阵中对应位置的数的绝对值进行加和
  • ¥15 活动选择题。最多可以参加几个项目?
  • ¥15 飞机曲面部件如机翼,壁板等具体的孔位模型
  • ¥15 vs2019中数据导出问题
  • ¥20 云服务Linux系统TCP-MSS值修改?
  • ¥20 关于#单片机#的问题:项目:使用模拟iic与ov2640通讯环境:F407问题:读取的ID号总是0xff,自己调了调发现在读从机数据时,SDA线上并未有信号变化(语言-c语言)
  • ¥20 怎么在stm32门禁成品上增加查询记录功能
  • ¥15 Source insight编写代码后使用CCS5.2版本import之后,代码跳到注释行里面
  • ¥50 NT4.0系统 STOP:0X0000007B
  • ¥15 想问一下stata17中这段代码哪里有问题呀