Google API日历v3令牌身份验证仅一次

时间:2015-07-11 10:22:39

标签: asp.net vb.net google-api google-calendar-api

我已经搜索了几天,但我无法得到答案,所以我创建了这篇文章。

我开发了一个网络应用,因此用户可以在自己的Google日历中创建活动。这是工作。但是,我无法想象,为什么这个应用程序只询问用户凭证一次。

例如:

  
      
  1. 用户John访问.aspx页面,然后他重定向到Google授权页面,因为这是John第一次访问该页面。
  2.   
  3. 经过授权,John可以在他的Google日历中创建一个活动。
  4.   

直到此步骤才有效。 John从他的谷歌帐户退出时出现问题。

  
      
  1. 如果Dave从另一台计算机访问此页面,则不会将其重定向到Google授权页面并突然直接创建一个事件   约翰的日历。
  2.   

有人可以帮助我,为什么会出现这个问题?

这是我的代码:

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 = "lpage@example.com" _
       }, New EventAttendee() With { _
           .Email = "sbrin@example.com" _
       }}, _
       .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

0 个答案:

没有答案