Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/337.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# Google Oauth响应文件中缺少刷新令牌_C#_Oauth 2.0_Google Oauth_Google Api Dotnet Client - Fatal编程技术网

C# Google Oauth响应文件中缺少刷新令牌

C# Google Oauth响应文件中缺少刷新令牌,c#,oauth-2.0,google-oauth,google-api-dotnet-client,C#,Oauth 2.0,Google Oauth,Google Api Dotnet Client,我正在使用Google的OAuth.Net库在ASP.NETMVC应用程序中实现GoogleOAuth。下面是我的代码 IAuthorizationCodeFlow flow = new GoogleAuthorizationCodeFlow( new GoogleAuthorizationCodeFlow.Initializer { ClientSecrets = new ClientSecrets { ** ClientId ** , ** ClientSecre

我正在使用Google的OAuth.Net库在ASP.NETMVC应用程序中实现GoogleOAuth。下面是我的代码

IAuthorizationCodeFlow flow = new GoogleAuthorizationCodeFlow(
  new GoogleAuthorizationCodeFlow.Initializer {
    ClientSecrets = new ClientSecrets {
        ** ClientId ** , ** ClientSecret **
      },
      DataStore = new FileDataStore( ** responsepath ** , true),
      Scopes = new [] {
        "https://www.googleapis.com/auth/userinfo.email",
        "https://www.googleapis.com/auth/gmail.send"
      },
      Prompt = "select_account"
  });

var userId = "user";
var uri = Request.Url.ToString();
var code = Request["code"];
if (code != null) {
  var token = flow.ExchangeCodeForTokenAsync(userId, code, uri.Substring(0, uri.IndexOf("?")), CancellationToken.None).Result;
  var oauthState = AuthWebUtility.ExtracRedirectFromState(flow.DataStore, userId, Request["state"]).Result;
  Response.Redirect(oauthState);
} else {
  var result = new AuthorizationCodeWebApp(flow, uri, uri).AuthorizeAsync(userId, CancellationToken.None).Result;

  if (result.RedirectUri != null) {
    Response.Redirect(result.RedirectUri);
  }
}
当用户点击谷歌登录按钮时,我的页面被重定向到谷歌认证页面。成功验证后,将再次显示“我的页面”。当我检查响应路径时,会创建下面的文件,其中包含访问令牌、到期时间等

Google.api.Auth.OAuth2.Responses.TokenResponse-user

当我在VisualStudio调试环境(IIS express)中本地运行上述代码时,上面的响应文件中有“refresh_token”。在生产环境(IIS)中部署相同的代码时,响应文件中缺少“刷新令牌”。我想知道背后的原因,因为我需要刷新令牌进行进一步处理


注意:在这两种情况下,我都在尝试之前从我的Google帐户中撤销了应用程序的访问权限。因此,这并不是说“刷新令牌”将仅在第一次发送。

在向Google发送请求时添加prompt=approve参数,每次都会给出刷新令牌,不会失败。

您可能希望尝试按照文档进行操作