当前位置: 首页 > 知识库问答 >
问题:

使用Google Coud Endpoints+Firebase身份验证“没有auth令牌附加到请求”

马清野
2023-03-14

我使用Google app Engine Standard Environment(Python)开发一个移动应用程序的后端,并使用Firebase进行身份验证。这个后端需要连接到用Unity创建的前端。

我在云endpoint读取登录Firebase后从Unity前端发送的身份验证令牌时遇到了麻烦。每次尝试发送经过身份验证的请求时,App Engine日志都会表示“没有auth令牌附加到请求”。

下面是在我的主Python文件中包含Firebase作为发行方的云endpoint声明:

@endpoints.api(name='connected', 
    version='v4.4.0', 
    allowed_client_ids=["32366828803-g14dan8j9m1dhises6namb5vpebopgpd.apps.googleusercontent.com "],
    issuers={'firebase': endpoints.Issuer('https://securetoken.google.com/fleet-fortress-211105',
    'https://www.googleapis.com/service_accounts/v1/metadata/x509/securetoken@system.gserviceaccount.com')})

下面是包含安全定义的swagger.yaml文件的结尾:

securityDefinitions:
    firebase:
        authorizationUrl: ''
        flow: implicit
        type: oauth2
        x-google-issuer: 'https://securetoken.google.com/fleet-fortress-211105'
        x-google-jwks_uri: 'https://www.googleapis.com/service_accounts/v1/metadata/x509/securetoken@system.gserviceaccount.com'
        x-google-audiences: "32366828803-g14dan8j9m1dhises6namb5vpebopgpd.apps.googleusercontent.com"

security:
    - firebase: []

我将从Firebase收到的auth令牌发送到授权头中的云endpointAPI(例如授权:承载{令牌})。

正在发送的标头:请求标头

以授权头作为承载发送的解码JWT:

{
"iss": "https://securetoken.google.com/fleet-fortress-211105",
"aud": "fleet-fortress-211105",
"auth_time": 1533831541,
"user_id": "8VdGVw9cF8V9QtfIZpgnD4DHKsY2",
"sub": "8VdGVw9cF8V9QtfIZpgnD4DHKsY2",
"iat": 1533831566,
"exp": 1533835166,
"email": "XXXX@gmail.com",
"email_verified": false,
"firebase": {
  "identities": {
    "email": [
      "XXXX@gmail.com"
    ]
  },
  "sign_in_provider": "password"
}
}

非常感谢在让我的GAE Cloud Endpoints后端读取JWT的授权头方面的任何帮助。

共有1个答案

督俊雅
2023-03-14

我不知道为什么这个错误会被记录下来;授权头正确地包含一个承载令牌,这是必需的。

但是,该错误消息实际上并不应该阻止身份验证的工作。(Python框架中的身份验证系统有点混乱,有两个并行的主要工作实现。)

相反,您需要在每个要保护的方法中调用endpoints.get_current_user()

 类似资料:
  • 当使用Firebase Auth进行身份验证时,我想自动输入通过SMS接收的代码。我能够接收短信并手动完成身份验证过程,但当我使用SmsRetriever时,应用程序崩溃,然后显示底部工作表对话框。这是Logcat中显示的所有内容: [SmsRetrieverHelper]SMS校验码请求失败:未知状态代码:17010 null 用户输入其电话号码的代码片段: 这是片段中的代码,用户必须在其中输入

  • 我有一个LaravelAPI(实际上是LumenAPI)服务于VueJS前端。Vue应用程序允许用户登录到谷歌。然后将Google令牌发送回Lumen API,后者使用Google验证令牌,然后验证电子邮件地址是否为有效用户。然后它生成一个令牌,与用户一起存储在数据库中,并返回用户对象。 我没有使用Passport或jwt auth之类的东西。那么现在,我如何使用默认的Auth中间件来验证(现在已

  • 您好,我正在尝试使用React、Express和Firebase创建一个具有身份验证的项目。在创建身份验证的过程中,我不知道为什么这种发送身份验证令牌的方式对我不起作用

  • 我正在按照以下官方链接将Digits身份验证迁移到Firebase身份验证: https://firebase.google.com/support/guides/digits-android https://github.com/firebase/FirebaseUI-Android/blob/master/auth/README.md <code>谷歌服务。从Firebase控制台导出的jso

  • 我正在尝试向正在运行的本地服务器发出GET请求。我无法返回正确的数据,我看到“未经授权”的响应。如果字符串“token”是正确的,那么任何人都能发现任何明显的问题吗。 }* 我能够从命令行获得一个curl请求:

  • } 要获取令牌,我执行以下步骤: > 使用浏览器转到:http://localhost:9000/oauth/authorize?response_type=code&client_id=test&redirect_uri=http%3a%2f%2flocalhost%3a8080%2f&scope=write 首先,它将我重定向到一个登录表单,在那里我输入用户名和密码:admin abc 请帮我