How to forget already given Oauth and ask for it again?

一笑奈何 提交于 2020-01-16 09:16:31

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!