3
我已經搜索了幾天,但我無法得到我的答案,所以我創建了這個帖子。Google API日曆v3令牌認證只有一次
我開發了一個網絡應用程序,所以用戶可以在他們的Google日曆中創建事件。這是工作。但是,我無法確定,爲什麼這個應用程序只會詢問用戶憑證一次。
例如:
- 用戶John訪問.aspx頁,然後他重新定向到谷歌授權的網頁,因爲它是約翰第一次訪問該頁面。
- 經過授權後,John可以在他的Google日曆中創建一個活動。
它一直工作到這一步。約翰從他的谷歌帳戶註銷時出現問題。
- 如果戴夫訪問從另一臺計算機此頁面,他不重定向到谷歌授權的頁面,突然直接創造的 約翰的日曆事件。
有人可以幫助我,爲什麼會出現這個問題?
這是我的代碼:
Protected Sub new_authentication()
Dim datafolder As String = Server.MapPath("App_Data/CalendarService.api.auth.store")
Dim scopes As IList(Of String) = New List(Of String)()
Dim UserId As String = "GoogleID_co"
scopes.Add(CalendarService.Scope.Calendar)
Dim myclientsecret As New ClientSecrets() With { _
.ClientId = myClientID, _
.ClientSecret = ClientSecret _
}
Dim flow As GoogleAuthorizationCodeFlow
flow = New GoogleAuthorizationCodeFlow(New GoogleAuthorizationCodeFlow.Initializer() With { _
.DataStore = New FileDataStore(datafolder), _
.ClientSecrets = myclientsecret, _
.Scopes = scopes _
})
Dim uri As String = Request.Url.ToString()
Dim code = Request("code")
If code IsNot Nothing Then
Dim token = flow.ExchangeCodeForTokenAsync(UserId, code, uri.Substring(0, uri.IndexOf("?")), CancellationToken.None).Result
' Extract the right state.
Dim oauthState = AuthWebUtility.ExtracRedirectFromState(flow.DataStore, UserId, Request("state")).Result
Response.Redirect(oauthState)
Else
Dim result = New AuthorizationCodeWebApp(flow, uri, uri).AuthorizeAsync(UserId, CancellationToken.None).Result
If result.RedirectUri IsNot Nothing Then
' Redirect the user to the authorization server.
Response.Redirect(result.RedirectUri)
Else
' The data store contains the user credential, so the user has been already authenticated.
myCalendarservice = New CalendarService(New BaseClientService.Initializer() With { _
.ApplicationName = "My Calendar", _
.HttpClientInitializer = result.Credential _
})
createcalendar()
End If
End If
End Sub
這是我createcalendar子
Protected Sub createcalendar()
Dim newEvent As New [Event]() With { _
.Summary = "Google I/O 2015", _
.Location = "800 Howard St., San Francisco, CA 94103", _
.Description = "A chance to hear more about Google's developer products.", _
.Start = New EventDateTime() With { _
.DateTime = DateTime.Parse("2015-07-13T09:00:00-07:00"), _
.TimeZone = "America/Los_Angeles" _
}, _
.[End] = New EventDateTime() With { _
.DateTime = DateTime.Parse("2015-07-14T17:00:00-07:00"), _
.TimeZone = "America/Los_Angeles" _
}, _
.Recurrence = New [String]() {"RRULE:FREQ=DAILY;COUNT=2"}, _
.Attendees = New EventAttendee() {New EventAttendee() With { _
.Email = "[email protected]" _
}, New EventAttendee() With { _
.Email = "[email protected]" _
}}, _
.Reminders = New [Event].RemindersData() With { _
.UseDefault = False, _
.[Overrides] = New EventReminder() {New EventReminder() With { _
.Method = "email", _
.Minutes = 24 * 60 _
}, New EventReminder() With { _
.Method = "sms", _
.Minutes = 10 _
}} _
} _
}
Dim calendarId As [String] = "primary"
Dim request As EventsResource.InsertRequest = myCalendarservice.Events.Insert(newEvent, calendarId)
Dim createdEvent As [Event] = request.Execute()
End Sub
什麼樣的價值也傳遞給暗淡碼=請求(「碼」)在這裏代碼?你在這裏存儲約翰的標記嗎?另外,要了解oauth流程,請檢查此oauth play https://developers.google.com/oauthplayground/,您可以在其中查看授權和身份驗證是如何完成的。 – SGC
如果您通過Google網頁授權重新導向,則代碼爲參數。 – Oscar