如何通过在 alexa 开发人员控制台中配置帐户链接部分来在 lambda 函数中获取 google oauth 刷新令牌? [英] How to get google oauth refresh token in the lambda function by configuring the account linking section in alexa developer console?

查看:36
本文介绍了如何通过在 alexa 开发人员控制台中配置帐户链接部分来在 lambda 函数中获取 google oauth 刷新令牌?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我参考了这个链接 https://medium.com/coinmonks/link-your-amazon-alexa-skill-with-a-google-api-within-5-minutes-7e488dc43168 并使用相同的配置说明.

I have referred this link https://medium.com/coinmonks/link-your-amazon-alexa-skill-with-a-google-api-within-5-minutes-7e488dc43168 and used same configuration as stated.

我能够在 lambda 函数中获取访问令牌 var accesstoken =handlerInput.requestEnvelope.context.System.user.accessToken;

I am able to get access token in the lambda function var accesstoken =handlerInput.requestEnvelope.context.System.user.accessToken;

如何通过配置alexa开发者控制台账号链接部分在handlerinput事件中获取refresh token?

How to get refresh token in the handlerinput event by configuring the alexa developer console account linking section?

我已经尝试在配套应用中启用/禁用技能,用模拟器测试,从谷歌自动访问中删除 alexa 技能,然后允许访问.

I have tried enable/disable skill in companion app,Tested with simulator,Removing alexa skill from the google auto access and then allowing access.

LaunchRequestHandler = {
  canHandle(handlerInput) {

    return handlerInput.requestEnvelope.request.type === 'LaunchRequest' || (handlerInput.requestEnvelope.request.type === 'IntentRequest' && handlerInput.requestEnvelope.request.intent.name === 'LaunchRequest');
  },
  async handle(handlerInput) {


    console.log('LAUNCH REQUEST CALLED');
    const speechText = 'Welcome!';
    if (handlerInput.requestEnvelope.context.System.user.accessToken === undefined) {
      console.log('ACCESS TOKEN NOT FOUND IN LAUNCH REQUEST');
      return handlerInput.responseBuilder
        .speak("ACCESS TOKEN NOT FOUND IN LAUNCH REQUEST")
        .reprompt("ACCESS TOKEN NOT FOUND IN LAUNCH REQUEST")
        .withLinkAccountCard()
        .withShouldEndSession(true)
        .getResponse();
    } 



     const fs = require('fs');
    const readline = require('readline');
    const { google } = require('googleapis');


    const SCOPES = ['https://www.googleapis.com/auth/userinfo.email','https://www.googleapis.com/auth/userinfo.profile','https://www.googleapis.com/auth/plus.me','https://www.googleapis.com/auth/tasks.readonly','https://www.googleapis.com/auth/tasks'];

function authorize() {

      return new Promise((resolve) => {
        const client_secret = process.env.client_secret;
        const client_id = process.env.client_id;
        const redirect_uris = ['*******************************', '*******************************', '*******************************'];
        const oAuth2Client = new google.auth.OAuth2(
          client_id, client_secret, redirect_uris[0]);

        console.log('access token found : ' + handlerInput.requestEnvelope.context.System.user.accessToken);

        oAuth2Client.credentials = { "access_token": handlerInput.requestEnvelope.context.System.user.accessToken };

推荐答案

刷新令牌不会暴露给 Alexa 的技能,换句话说:您的技能代码无法访问刷新令牌,这完全由 Alexa 管理.当您的客户将访问您的技能并且访问令牌即将到期时,Alexa 将在后台使用刷新令牌向您的身份提供商(在您的情况下为 Google)询问一个新令牌.

The refresh token is not exposed to the Skill by Alexa, in other words : there is no way for your skill code to get access to the refresh token, this is entirely managed by Alexa. Alexa will use the refresh token behind the scene to ask your Identity Provider (Google in your case) a fresh token when your customer will access your skill and the access token is about to expire.

这在 https://developer.amazon.com/docs/account-linking/account-linking-for-custom-skills.html#choose-auth-type-overview

这篇关于如何通过在 alexa 开发人员控制台中配置帐户链接部分来在 lambda 函数中获取 google oauth 刷新令牌?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆