2014-11-25 149 views
0

我无法弄清楚如何通过重定向url来完成OAuth2授权。谷歌REST API表示REDIRECT_URL参数可以传递但这.NET API似乎并未有一个功能,通过重定向URLGoogle OAuth2重定向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参数总是对一些随机的网址(例如,http://localhost:<random port number>/Authorize不知道这是哪里值从哪里来API控制台中,我已经设置http://localhost:4444/Home/Index由于没有匹配,认证抛出错误:。以上redirect_uri_mismatch

代码结果到这个请求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/从哪里来?

任何关于如何在代码中设置redirect_uri参数的指针?

回答

1

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