首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >使用Firebase Auth,希望使用JWT到Auth客户端(iOS应用程序)发送MongoDB请求

使用Firebase Auth,希望使用JWT到Auth客户端(iOS应用程序)发送MongoDB请求
EN

Stack Overflow用户
提问于 2021-03-18 04:14:39
回答 1查看 223关注 0票数 1

我目前正在使用Firebase Auth对所有用户进行身份验证,并使用mongodb王国/领域同步/地图集作为我的数据库。据我所知,使用两个独立的'auths‘(firebase和mongo)并将它们与Firebase UID作为密钥链接似乎是个坏主意。因此,JWT似乎是我最好的选择。

我觉得下面的代码是a-ok的,但是领域应用程序上的配置是不确定的:当我使用自定义的JWT令牌时,公共密钥没有被格式化,当我使用JWK (https://www.googleapis.com/robot/v1/metadata/x509/securetoken@system.gserviceaccount.com)时,我得到以下错误:

登录失败:从URI获取JWK :未能从键中构造密钥:不支持的kty类型错误Domain=realm::app::ServiceError Code=47“从URI中获取JWK :从键中获取密钥失败:不支持的kty类型”UserInfo={NSLocalizedDescription=failed从URI中获取JWK :从键中失败构建密钥:不支持的kty类型,realm::app::ServiceError=AuthError}

代码语言:javascript
复制
// Function is supposed to auth user using mongo auth by using the firebase jwt
func authJWTMongo(completion: @escaping (Bool) -> Void) -> Void{
        let currentUser = Auth.auth().currentUser
        currentUser?.getIDTokenForcingRefresh(true) { idToken, error in
            if error != nil {
                print("Totally f'ed the mongoAuth")
                completion(false)
                return;
            }

            // Auth using Mongo shit
            print("JWT is< \(String(describing: idToken))>")
            if let idToken = idToken{
                let credentials = Credentials.jwt(token: idToken)
                app.login(credentials: credentials) { (result) in
                    switch result {
                    case .failure(let error):
                        print("Login failed: \(error.localizedDescription)")
                        print("\(error)")
                        completion(false)
                    case .success(let user):
                        print("Successfully logged in as user \(user)")
                        completion(true)
                        // Now logged in, do something with user
                        // Remember to dispatch to main if you are doing anything on the UI thread
                    }
                }
            }
        }
    }

任何帮助都是非常感谢的。

EN

回答 1

Stack Overflow用户

发布于 2021-03-18 22:56:48

显然正确的JWK URI是https://www.googleapis.com/service_accounts/v1/jwk/securetoken@system.gserviceaccount.com

上面的快速密码没什么问题。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/66684686

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档