简体   繁体   English

在没有SDK的Google上的Actions中发送通知

[英]Send notification in Actions on Google without SDK

I am implementing notifications within an action. 我正在执行一个动作中的通知。 I am able to register users. 我可以注册用户。 However, I am not able to figure out how to do the push notification. 但是,我无法弄清楚如何进行推送通知。

As the sample code uses the SDK, I am now stuck at the part "Exchange key for an access token" found in this documentation . 当示例代码使用SDK时,我现在停留在本文档中的 “访问令牌的交换密钥”部分。

Is it possible to do this without the SDK? 没有SDK,是否可以这样做? using a rest service? 使用休息服务?

Yes... but... 对,但是...

There is a REST service that does this, in fact, the library ultimately calls it. 有一个REST服务可以执行此操作,实际上,库最终会调用它。 It is the standard OAuth2 token exchange endpoint at https://www.googleapis.com/oauth2/v4/token . 它是https://www.googleapis.com/oauth2/v4/token的标准OAuth2令牌交换端点。 The catch is building the JWT that you can pass to this service. 问题在于构建了可以传递给该服务的JWT。 To quote Google's page on the subject : 引用Google 在该主题上页面

Although your application can complete these tasks by directly interacting with the OAuth 2.0 system using HTTP, the mechanics of server-to-server authentication interactions require applications to create and cryptographically sign JSON Web Tokens (JWTs), and it's easy to make serious errors that can have a severe impact on the security of your application. 尽管您的应用程序可以通过使用HTTP直接与OAuth 2.0系统进行交互来完成这些任务,但是服务器到服务器身份验证交互的机制要求应用程序创建并用密码对JSON Web令牌(JWT)进行签名,而且很容易造成严重的错误,可能会严重影响应用程序的安全性。

For this reason, we strongly encourage you to use libraries, such as the Google APIs client libraries, that abstract the cryptography away from your application code. 因此,我们强烈建议您使用诸如Google API客户端库之类的库,该库将加密技术从您的应用程序代码中抽象出来。

In short, if you want to do this, you need to: 简而言之,如果要执行此操作,则需要:

  1. Create a JSON Web Token (JWT) which includes a header, a claim set, and a signature. 创建一个JSON Web令牌(JWT),其中包括标头,声明集和签名。
  2. Request an access token from the Google OAuth 2.0 Authorization Server. 向Google OAuth 2.0授权服务器请求访问令牌。
  3. Handle the JSON response to get the access token. 处理JSON响应以获取访问令牌。
  4. Keep track of the lifespan of the access token and, when it expires and you need an access token, repeat steps 1-4. 跟踪访问令牌的寿命,当它过期并且您需要访问令牌时,请重复步骤1-4。

Details are at Using OAuth 2.0 for Server to Server Applications 有关详细信息,请参见使用OAuth 2.0进行服务器到服务器的应用程序

I'm not familiar with C# libraries, however I've been told that Google's C# Client Library seems to support it, and the high level documentation for ServiceAccountCredential appears to be able to generate auth tokens from the credentials. 我不熟悉C#库,但是有人告诉我Google的C#客户端库似乎支持它,而且ServiceAccountCredential的高级文档似乎能够从凭据生成身份验证令牌。

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM