2014-11-25 69 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通常會尋找一個。