Firebase REST APIのラッパーを書き込もうとすると(完全なソースについてはhttps://github.com/cloudfuji/taikaを参照)、認証トークンが失敗しているようです。関数は、Firebaseが提供するJavaライブラリオプション(https://github.com/firebase/firebase-token-generator-java)の単純なラッパーです。
コードは単純です:
(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 "example@example.com" :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." }
ルビーライブラリには同じ問題はないようです。
繰り返しになりますが、完全なソースソースはhttps://github.com/cloudfuji/taika/blob/master/src/taika/auth.cljにあります