首页 > 解决方案 > 授权设备访问时没有刷新令牌

问题描述

我能够通过合作伙伴连接管理器成功授权用户,但是当我https://www.googleapis.com/oauth2/v4/token使用我的授权代码请求令牌时,我没有refresh_token在响应中收到 a,只有一个access_token存在:

{
  access_token: 'my-access-token',
  expires_in: 3599,
  scope: 'https://www.googleapis.com/auth/sdm.service',
  token_type: 'Bearer'
}

标签: nest-device-access

解决方案


确保access_type=offline在您的合作伙伴连接管理器 (PCM) URL 中指定。省略它假定access_type=online不提供刷新令牌。

例如,PCM URL 应如下所示,其中access_type=offline

https://nestservices.google.com/partnerconnections/project-id/auth?
  redirect_uri=my-redirect-uri&
  access_type=offline&
  prompt=consent&
  client_id=my-client-id&
  response_type=code&
  scope=https://www.googleapis.com/auth/sdm.service

然后,随后的令牌响应https://www.googleapis.com/oauth2/v4/token应该具有您的期望:

{
  "access_token": "my-access-token",
  "expires_in": 3599,
  "refresh_token": "my-refresh-token",
  "scope": "https://www.googleapis.com/auth/sdm.service",
  "token_type": "Bearer"
}

有关详细信息,请参阅在设备访​​问站点上授权帐户。


推荐阅读