简体   繁体   English

Azure SendGrid 提供的授权授权无效、过期或撤销

[英]Azure SendGrid The provided authorization grant is invalid, expired, or revoked

I have created a built in azure function to send email using SendGrid from the available options in azure, here is my code I have created a built in azure function to send email using SendGrid from the available options in azure, here is my code

I used develop in portal option from azure我在 azure 的门户选项中使用了开发

// The 'From' and 'To' fields are automatically populated with the values specified by the binding settings.
//
// You can also optionally configure the default From/To addresses globally via host.config, e.g.:
//
// {
//   "sendGrid": {
//      "to": "user@host.com",
//      "from": "Azure Functions <samples@functions.com>"
//   }
// }
#r "SendGrid"

using System;
using SendGrid.Helpers.Mail;
using Microsoft.Azure.WebJobs.Host;

public static SendGridMessage Run(Order order, ILogger log)
{
    log.LogInformation($"C# Queue trigger function processed order: {order.OrderId}");

    SendGridMessage message = new SendGridMessage()
    {
        Subject = $"Thanks for your order (#{order.OrderId})!",
        From = new EmailAddress("from@outlook.com"),
    };
    
    message.AddTo(order.CustomerEmail, order.CustomerName);
    message.AddContent("text/plain", $"{order.CustomerName}, your order ({order.OrderId}) is being processed!");
    return message;
}
public class Order
{
    public string OrderId { get; set; }
    public string CustomerName { get; set; }
    public string CustomerEmail { get; set; }
}

I have my json as follows我的 json 如下

{
  "bindings": [
    {
      "type": "queueTrigger",
      "name": "order",
      "direction": "in",
      "queueName": "samples-orders"
    },
    {
      "type": "sendGrid",
      "name": "$return",
      "direction": "out",
      "apiKey": "FUNCTIONS_EXTENSION_VERSION"
    }
  ]
}

When I manually trigger it I am getting an error as mentioned I tried changing the api key but some how it is resetting当我手动触发它时,我收到一个错误,如前所述,我尝试更改 api 键,但有些如何重置

Can some one help me how to resolve the error有人可以帮我解决错误吗

If I recall correctly, you should set the name of your SendGrid API key AppSetting to the apiKey parameter in the SendGrid binding.如果我没记错的话,您应该将 SendGrid API 键 AppSetting 的名称设置为 SendGrid 绑定中的apiKey参数。 So instead of "apiKey": "FUNCTIONS_EXTENSION_VERSION" it should be "apiKey": "MySendGridApiKey" or replace MySendGridApiKey with whatever name you'd like to give the AppSetting.因此,应该是"apiKey": "MySendGridApiKey" ,而不是"apiKey": "FUNCTIONS_EXTENSION_VERSION" ,或者将MySendGridApiKey替换为您希望为 AppSetting 提供的任何名称。

Then, in your Azure Function AppSettings, create an AppSetting with the same name and set the value to your SendGrid API key.然后,在您的 Azure Function AppSettings 中,创建一个具有相同名称的 AppSetting 并将值设置为您的 SendGrid API 键。

You can read more about creating your API Key here , and read more about managing AppSettings in Azure Functions here .您可以在此处阅读有关创建 API 密钥的更多信息,并在此处阅读有关在 Azure 函数中管理 AppSettings 的更多信息。

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

相关问题 SendGrid API 密钥不起作用。 “提供的授权授权无效、过期或撤销” - SendGrid API Key is not working. "The provided authorization grant is invalid, expired or revoked" Google 令牌已过期或被撤销 - Google Token has been expired or revoked 使用无服务器框架在 lambda AWS 中授予授权代码 - Authorization code grant in lambda AWS with Serverless Framework Firebase 管理员 getUser 无效授权 - Firebase admin getUser invalid grant 在 sendgrid API 中实现“/messages”端点时出现授权异常 - Authorization Exception While implementing "/messages" endpoint in sendgrid API MacOS Sierra 上的“授权令牌已过期”问题 AWS-CLI - `Authorization Token has expired` issue AWS-CLI on MacOS Sierra 错误:invalid_grant,用于使用刷新令牌获取访问令牌 - error: invalid_grant , for getting access token using refresh token 在 oauth2.0 授权代码授权流程中获取新的刷新令牌 - Get new refresh token in oauth2.0 authorization code grant flow 无效的 AttributeDataType 输入,考虑使用提供的 AttributeDataType 枚举 - Invalid AttributeDataType input, consider using the provided AttributeDataType enum 不支持您提供的授权机制。 请使用 AWS4-HMAC-SHA256 - The authorization mechanism you have provided is not supported. Please use AWS4-HMAC-SHA256
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM