问题
In the official sample C# code for YouTube OAuth login, adding a Scope once after the user already given access to the application does not seem to work. (In this case, the user was myself.) I went to the third-party access page of my Google account and manually removed the application. But when I ran the app again, it did not show the OAuth page again, but simply passed the code and failed at the actual API call with "Token has been revoked.".
I did not know how to remove the existing authentication, so I came up with a workaround of adding "2" to ApplicationName
. But that's stupid. How to remove the authentication and get it again for changed scopes?
UserCredential credential;
using (var stream = new FileStream("client_secrets.json", FileMode.Open, FileAccess.Read))
{
credential = await GoogleWebAuthorizationBroker.AuthorizeAsync(
GoogleClientSecrets.Load(stream).Secrets,
// This OAuth 2.0 access scope allows for full read/write access to the
// authenticated user's account.
new[] { YouTubeService.Scope.Youtube, YouTubeService.Scope.YoutubeForceSsl },
"user",
CancellationToken.None,
new FileDataStore(this.GetType().ToString())
);
}
var youtubeService = new YouTubeService(new BaseClientService.Initializer()
{
HttpClientInitializer = credential,
ApplicationName = this.GetType().ToString() +"2"
});
来源:https://stackoverflow.com/questions/57940262/how-to-forget-already-given-oauth-and-ask-for-it-again