简体   繁体   English

Firebase ID 令牌的受众 (aud) 声明不正确。 预期 确保 ID 令牌来自与 Firebase 相同的项目

[英]Firebase ID token has incorrect audience (aud) claim. Expected Make sure the ID token comes from the same Firebase project as the

I use Firebase Admin .NET SDK with the.Net 6 web API project for Google login.我使用Firebase Admin .NET SDK和 .Net 6 web API 项目进行 Google 登录。 The below code is working fine in the local environment.下面的代码在本地环境中运行良好。 But when I published the app to Azure App service it gives the below error.但是当我将应用程序发布到 Azure 应用程序服务时,出现以下错误。 I think the issue here is with initializing the "FirebaseAdminSdk.json" file.我认为这里的问题在于初始化"FirebaseAdminSdk.json"文件。 Do you know how to do it in production?你知道如何在生产中做到这一点吗?

Firebase ID token has incorrect audience (aud) claim. Firebase ID 令牌的受众 (aud) 声明不正确。 Expected my-firebase-project-id but got 272437162012-hagu0iffquo1lb3ko07qtpgenluswaebr.apps.googleusercontent.com.预期为 my-firebase-project-id 但得到 272437162012-hagu0iffquo1lb3ko07qtpgenluswaebr.apps.googleusercontent.com。 Make sure the ID token comes from the same Firebase project as the credential used to initialize this SDK确保 ID 令牌来自与用于初始化此 SDK 的凭据相同的 Firebase 项目

Extension method扩展方法

 public static void ConfigureFirebaseAdminSdk(this IServiceCollection services,
        IConfiguration configuration)
    {
       
        var pathToFirebaseAdminSdk = Path.Combine(Directory.GetCurrentDirectory(),
                           "keys", "FirebaseAdminSdk.json"); // I think problem is here

        FirebaseApp.Create(new AppOptions
        {
            Credential = GoogleCredential.FromFile(pathToFirebaseAdminSdk)
        });

        services.AddAuthentication(JwtBearerDefaults.AuthenticationScheme)
               .AddJwtBearer(options =>
               {
                   var firebaseProjectId = configuration["FirebaseProjectId"];

                   var firebaseSecureTokenUrl = configuration["FirebaseSecureTokenUrl"];

                   options.Authority = firebaseSecureTokenUrl + firebaseProjectId;

                   options.TokenValidationParameters = new TokenValidationParameters
                   {
                       ValidateIssuer = true,
                       ValidIssuer = firebaseSecureTokenUrl + firebaseProjectId,
                       ValidateAudience = true,
                       ValidAudience = firebaseProjectId,
                       ValidateLifetime = true
                   };
               });
    }

As the error message says, your FirebaseAdminSdk.json is for a different project than where you are running the code.如错误消息所述,您的FirebaseAdminSdk.json与您运行代码的项目不同。 From the my-firebase-project-id in the message it seems that it may be from your local emulator project.从消息中的my-firebase-project-id看来,它可能来自您本地的模拟器项目。

You will need to make sure the JSON file and the configuration["FirebaseProjectId"] are for the same project.您需要确保 JSON 文件和configuration["FirebaseProjectId"]用于同一个项目。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 从连接到 Google Functions 的端点调用时,Firebase ID 令牌具有不正确的“aud”(受众)声明 - Firebase ID token has incorrect "aud" (audience) claim when calling from Endpoint connected to Google Functions Firebase ID 令牌即使在 jwt 上也有无效签名 - Firebase ID token has invalid signature even on jwt Firebase Auth:如何使用id token登录? - Firebase Auth: How to sign in using id token? 在 Expo 中使用 Firebase 验证 Google 提供的 ID Token - Verify ID Token provided by Google with Firebase in Expo Firebase Auth ID 令牌验证的必要性,即使有数据库的安全规则? - Necessity of Firebase Auth ID token validation, even if there are security rules of database? 如何使用Cloud Run和Swift验证Firebase ID Token? - How To Verify Firebase ID Token Using Cloud Run and Swift? 登录Firebase auth,在flutter测试中获取Id token - Log in Firebase auth and get Id token in flutter tests firebase_admin auth.verify_id_token 很慢 - firebase_admin auth.verify_id_token is very slow 在客户端检索由 firebase 分配的用户 ID 令牌时出错 - error retrieving user Id token assigned by firebase in the client side 在检索发件人 ID 的 FCM 令牌之前未设置 APNS 设备令牌 - React Native Firebase - APNS device token not set before retrieving FCM Token for Sender ID - React Native Firebase
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM