具有自定义令牌的Firebase身份验证

编程入门 行业动态 更新时间:2024-10-24 18:24:55
本文介绍了具有自定义令牌的Firebase身份验证的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我有一个firebase项目,我试图从我的rails服务器进行身份验证,并使用ruby-jwt库创建了一个自定义令牌,如文档中所述,但是我一直遇到相同的错误:

I have a firebase project which Im trying to authenticate from my rails server creating a custom token with the library ruby-jwt as it says on the docs, but i keep getting the same error:

auth/invalid-custom-token,自定义令牌格式不正确.请检查文档.

auth/invalid-custom-token, The custom token format is incorrect. Please check the documentation.

credentials.json来自我在Google控制台中创建的服务帐户,uid从前端发送到api.

The credentials.json is from the service account I made in google console, uid is sent from the front end to the 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 => 'identitytoolkit.googleapis/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') end

在jwt.io中看起来像这样

it looks like this in jwt.io

{ "iss": "defered@defered.iam.gserviceaccount", "sub": "defered@defered.iam.gserviceaccount", "aud": "identitytoolkit.googleapis/google.identity.identitytoolkit.v1.IdentityToolkit", "iat": 1486824545, "exp": 1486828145, "uid": "4", "claims": { "premium_account": true } }

推荐答案

我找到了一种更好的身份验证方法,我只是发送firebase给您的令牌,并使用我需要的信息在正轨上对其进行验证,仅此而已.

I found a better way to authenticate, I'm just sending the token that firebase gives you and verifying it on rails with the information I need and that's it.

更多推荐

具有自定义令牌的Firebase身份验证

本文发布于:2023-11-04 00:51:17,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1556508.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:令牌   自定义   身份验证   Firebase

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!