簡體   English   中英

Alexa 帳戶鏈接 - 如果鏈接的訪問令牌已過期怎么辦? 我正在使用隱式授權流程

[英]Alexa Account Linking - What to do if access token linked is expired? I am using Implicit grant flow

我正在嘗試使用隱式授權流程進行 alexa 帳戶鏈接。 我的訪問令牌的有效期僅為一年。

  1. 如何要求用戶再次登錄以獲取新的訪問令牌?
  2. 我可以與亞馬遜共享刷新令牌而不是訪問令牌嗎?

在您的 API 中檢查訪問令牌是否仍然有效。 如果不是,則發送帳戶鏈接卡並告訴用戶他們需要檢查他們的 Alexa 應用程序以重新鏈接他們的帳戶。 以下是使用適用於 Node.jsAlexa Skills Kit SDK (v2)發送帳戶關聯卡的方法(請參閱 withLinkAccountCard() 調用):

const OrderCarIntentHandler = {

  // ...

  handle(handlerInput){

    // This intent requires an access token so that we can get the user's
    // Ride Hailer user profile with payment information.

    // The access token is in the Context object. Access the
    // request in the HandlerInput object passed to the
    // handler.

    var accessToken = handlerInput.requestEnvelope.context.System.user.accessToken;

    if (accessToken == undefined){
        // The request did not include a token, so tell the user to link
        // accounts and return a LinkAccount card
        var speechText = "You must have a Ride Hailer account to order a car. " +
                    "Please use the Alexa app to link your Amazon account " +
                    "with your Ride Hailer Account.";

        return handlerInput.responseBuilder
            .speak(speechText)
            .withLinkAccountCard()
            .getResponse();
    } else {

        // Use the token to access the user's profile. This should also verify that the
        // token represents a valid Ride Hailer user.

        // ...

    }
  }
}; 

https://developer.amazon.com/en-US/docs/alexa/custom-skills/include-a-card-in-your-skills-response.html#define-a-card-for-use-with-帳戶關聯

用戶現在需要重新鏈接帳戶並獲取新的訪問令牌。

如果您需要刷新令牌,請使用授權代碼授權而不是隱式授權。

希望這可以幫助!

如果您使用的是隱式授予,則沒有刷新令牌。 你想做什么,當令牌過期時,顯示卡重定向到你的授權服務器。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM