尝试在 .net 中发送消息时收到“来自 APNS 或 Web 推送服务的身份验证错误”

问题描述 投票:0回答:1

我正在尝试使用 Firebase Cloud Messaging API (V1) 发送通知。

这是用于发送消息的操作方法。

    [HttpPost("notification")]
    public async Task<IActionResult> SendMessage(SingleMessageRequest request)
    {
        var messaging = FirebaseMessaging.DefaultInstance;
        if (messaging == null)
        {
            notificationService.GetFirebaseApp();
            messaging = FirebaseMessaging.DefaultInstance;
        }

        var message = new Message()
        {
            Data = new Dictionary<string, string>()
            {
                ["Name"] = request.data.Name,
                ["Email"] = request.data.Email
            },
            Notification = new FirebaseAdmin.Messaging.Notification
            {
                Title = request.notification.title,
                Body = request.notification.body
            },
            Token = request.token,
            //Topic = request.topic
        };

        var result = await messaging.SendAsync(message);
        return new OkObjectResult(result);
    }

这里

notificationService.GetFirebaseApp();
是在单独的服务中设置firebase配置的方法。

    public interface INotificationService
    {
        public FirebaseApp GetFirebaseApp();
    }

    public class NotificationService : INotificationService
    {
        public FirebaseApp GetFirebaseApp()
        {
            var credentials = FirebaseApp.Create(new AppOptions()
            {
                Credential = GoogleCredential.FromFile(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "key.json")),
            });

            return credentials;
        }
    }

enter image description here

这是从帐户生成的secretKey.json文件。

在 React 应用程序中,我使用相同的项目配置详细信息。并且还能够生成设备令牌。但是,当我尝试使用 .net api 项目发送消息时,出现错误“来自 APNS 或 Web 推送服务的身份验证错误”。

我已经检查了所有权限和其他内容,但该帐户拥有所有权限。

不是,我无法在这里找到原因。有人可以帮我吗?

谢谢

错误:

FirebaseAdmin.Messaging.FirebaseMessagingException: Auth error from APNS or Web Push Service
   at FirebaseAdmin.Util.ErrorHandlingHttpClient`1.SendAndReadAsync(HttpRequestMessage request, CancellationToken cancellationToken)
   at FirebaseAdmin.Util.ErrorHandlingHttpClient`1.SendAndDeserializeAsync[TResult](HttpRequestMessage request, CancellationToken cancellationToken)
   at FirebaseAdmin.Messaging.FirebaseMessagingClient.SendAsync(Message message, Boolean dryRun, CancellationToken cancellationToken)
   at FirebaseAdmin.Messaging.FirebaseMessaging.SendAsync(Message message, Boolean dryRun, CancellationToken cancellationToken)
   at FirebaseAdmin.Messaging.FirebaseMessaging.SendAsync(Message message, Boolean dryRun)
   at FirebaseAdmin.Messaging.FirebaseMessaging.SendAsync(Message message)
   at FirebaseCloudMessagingPOC.Controllers.NotificationController.SendMessage(SingleMessageRequest request) in C:\Users\Vijay.Parmar\source\repos\FirebaseCloudMessagingPOC\FirebaseCloudMessagingPOC\Controllers\NotificationController.cs:line 73
   at Microsoft.AspNetCore.Mvc.Infrastructure.ActionMethodExecutor.TaskOfIActionResultExecutor.Execute(IActionResultTypeMapper mapper, ObjectMethodExecutor executor, Object controller, Object[] arguments)
   at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.<InvokeActionMethodAsync>g__Awaited|12_0(ControllerActionInvoker invoker, ValueTask`1 actionResultValueTask)
   at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.<InvokeNextActionFilterAsync>g__Awaited|10_0(ControllerActionInvoker invoker, Task lastTask, State next, Scope scope, Object state, Boolean isCompleted)
   at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.Rethrow(ActionExecutedContextSealed context)
   at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.Next(State& next, Scope& scope, Object& state, Boolean& isCompleted)
   at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.<InvokeInnerFilterAsync>g__Awaited|13_0(ControllerActionInvoker invoker, Task lastTask, State next, Scope scope, Object state, Boolean isCompleted)
   at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.<InvokeFilterPipelineAsync>g__Awaited|20_0(ResourceInvoker invoker, Task lastTask, State next, Scope scope, Object state, Boolean isCompleted)
   at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.<InvokeAsync>g__Awaited|17_0(ResourceInvoker invoker, Task task, IDisposable scope)
   at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.<InvokeAsync>g__Awaited|17_0(ResourceInvoker invoker, Task task, IDisposable scope)
   at Microsoft.AspNetCore.Routing.EndpointMiddleware.<Invoke>g__AwaitRequestTask|6_0(Endpoint endpoint, Task requestTask, ILogger logger)
   at Microsoft.AspNetCore.Authorization.AuthorizationMiddleware.Invoke(HttpContext context)
   at Swashbuckle.AspNetCore.SwaggerUI.SwaggerUIMiddleware.Invoke(HttpContext httpContext)
   at Swashbuckle.AspNetCore.Swagger.SwaggerMiddleware.Invoke(HttpContext httpContext, ISwaggerProvider swaggerProvider)
   at Microsoft.AspNetCore.Diagnostics.DeveloperExceptionPageMiddleware.Invoke(HttpContext context)

enter image description here

c# firebase firebase-cloud-messaging web-push
1个回答
0
投票

清除 cookies 帮我完成了这项工作。

© www.soinside.com 2019 - 2024. All rights reserved.