我目前正在使用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}
// 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
}
}
}
}
}任何帮助都是非常感谢的。
发布于 2021-03-18 22:56:48
显然正确的JWK URI是https://www.googleapis.com/service_accounts/v1/jwk/securetoken@system.gserviceaccount.com
上面的快速密码没什么问题。
https://stackoverflow.com/questions/66684686
复制相似问题