Google OAuth2 重定向 URL 问题 [英] Google OAuth2 Redirect URL Issues

查看:219
本文介绍了Google OAuth2 重定向 URL 问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我不知道如何传递重定向 url 来完成 OAuth2 授权.Google REST API 表示可以传递redirect_url 参数,但是这个.Net API 似乎没有传递redirect url 的功能

I cannot figure out how to pass a redirect url to accomplish OAuth2 authorization. Google REST API indicates that redirect_url parameters can be passed but this .Net API does not seem to have a feature to pass redirect url

Dim Coll As New List(Of String)

Coll.Add(CalendarService.Scope.Calendar)
Coll.Add(Google.Apis.Tasks.v1.TasksService.Scope.Tasks)

Dim credential As UserCredential = GoogleWebAuthorizationBroker.AuthorizeAsync(New ClientSecrets() With { _
                .ClientId = ClientCredentials.ClientID, _
                .ClientSecret = ClientCredentials.ClientSecret _
                 }, Coll, "user", CancellationToken.None, New SavedDataStore(myStoredResponse)).Result

Dim CalService = New CalendarService(New BaseClientService.Initializer() With { _
                .HttpClientInitializer = credential, _
                .ApplicationName = "myApp"})

执行此代码时会启动浏览器实例,但该请求中的 return_url 参数始终指向某个随机 url(例如,http://localhost:<random port number>/Authorize. 不知道这个值是从哪里来的,在API控制台中,我设置了http://localhost:4444/Home/Index,由于没有匹配,认证抛出错误:redirect_uri_mismatch

A browser instance is launched when this code is executed but the return_url parameter in that request is always to to some random url (e.g., http://localhost:<random port number>/Authorize. Don't know where is this value coming from. In the API console, I have set http://localhost:4444/Home/Index. Since there is no match, authentication throws Error: redirect_uri_mismatch

上面的代码导致这个请求url

The above code results into this request url

https://accounts.google.com/o/oauth2/auth?access_type=offline&response_type=code&client_id=589627125301.apps.googleusercontent.com&redirect_uri=http://localhost:44933/authorize/&scope=https://www.googleapis.com/auth/calendar https://www.googleapis.com/auth/tasks

总而言之,问题是,这个 http://localhost:44933/authorize/ 来自哪里?

In summary the question is, where is this http://localhost:44933/authorize/ coming from?

有关如何在代码中设置此 redirect_uri 参数的任何指示?

Any pointers as to how to set this redirect_uri parameter in the code?

推荐答案

尝试添加 .CallbackURL 属性.Google API 通常会寻找一个.

Try adding a .CallbackURL property. Google API usually looks for one.

这篇关于Google OAuth2 重定向 URL 问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆