0
尝试编写围绕Firebase REST API编写包装(有关完整源代码,请参阅https://github.com/cloudfuji/taika),并且认证令牌似乎失败。该功能是围绕着火力地堡提供的Java库选项(https://github.com/firebase/firebase-token-generator-java)“错误”:“invalid_token:无法解析授权令牌。”在Clojure中为Firebase生成JWT
简单封装代码很简单:
(ns taika.auth
(:require [clojure.string :as string]
[clj-http.client :as client]
[cheshire.core :as json])
(:import [com.firebase.firebase-token-generator.security.token]
[org.json.JSONOBject]))
(defn token-generator [secret-key]
(com.firebase.security.token.TokenGenerator. secret-key))
(defn create-token [token-generator auth-data & [admin?]]
(let [token-options (doto (com.firebase.security.token.TokenOptions.)
(.setAdmin (or admin? false)))]
(.createToken token-generator (org.json.JSONObject. auth-data) token-options)))
生成的令牌,看起来是合理的(例如秘密密钥,当然):
(let [tg (token-generator "abc123")
auth-data {:email "[email protected]" :api_key "my-api-key"}
admin? false]
(create-token tg auth-data admin?))
=> "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ2IjowLCJpYXQiOjEzNjIxNjEzMDJ9.8701406fad76b2dff83bf38a18d91a95ed7787f255e7dd534a77e7daa0c58c59"
但在REST API请求使用令牌时,它失败:
{ "error" : "invalid_token: Could not parse auth token." }
ruby库似乎没有相同的问题。
此外,全源源是https://github.com/cloudfuji/taika/blob/master/src/taika/auth.clj