Tag: firebase authentication

使用自定义令牌的Firebase身份validation

我有一个firebase项目,我试图从我的rails服务器进行身份validation,创建一个自定义令牌与库ruby-jwt,就像在文档上说的那样,但我一直得到同样的错误: auth / invalid-custom-token,自定义标记格式不正确。 请查看文档。 credentials.json来自我在谷歌控制台中创建的服务帐户,uid从前端发送到api。 def generate_auth_token(uid) now_seconds = Time.now.to_i credentials = JSON.parse(File.read(“credentials.json”)) private_key = OpenSSL::PKey::RSA.new credentials[“private_key”] payload = { :iss => credentials[“client_email”], :sub => credentials[“client_email”], :aud => ‘https://identitytoolkit.googleapis.com/google.identity.identitytoolkit.v1.IdentityToolkit’, :iat => now_seconds, :exp => now_seconds+(60*60), # Maximum expiration time is one hour :uid => uid.to_s, :claims => {:premium_account => true} } JWT.encode(payload, private_key, ‘RS256’) […]