Как да отмените токен за потребител

Как мога да направя, за да оттегля токена за потребител?

Това е моят код за удостоверяване и искам да нулирам (отменя) достъпа за един потребител. Това е така, защото използвам API на GMail и искам да позволя на моя потребител да промени имейла си, ако е необходимо .

Всъщност токените се запазват с влизане в момента, в който токенът е достигнат, но трябва да променя тази стойност, когато потребителят реши да промени своя имейл.

Dim datafolder As String = Server.MapPath("App_Data/GoogleService.api.auth.store")
        Dim scopes As IList(Of String) = New List(Of String)()
        Dim UserId As String = Context.User.Identity.Name.ToString

        scopes.Add(DriveService.Scope.Drive)
        scopes.Add(GmailService.Scope.MailGoogleCom)
        Dim myclientsecret As New ClientSecrets() With { _
          .ClientId = CLIENT_ID, _
          .ClientSecret = CLIENT_SECRET _
        }

        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.
                myDriveService = New DriveService(New BaseClientService.Initializer() With { _
                  .ApplicationName = "Liens Google SyGED", _
                  .HttpClientInitializer = result.Credential _
                })

                myGMailService = New GmailService(New BaseClientService.Initializer() With { _
               .ApplicationName = "Liens Google SyGED", _
               .HttpClientInitializer = result.Credential _
             })

            End If
        End If

person PGSolutions SyGED    schedule 01.06.2015    source източник
comment
Опитахте ли просто да изтриете файла за userid?   -  person DaImTo    schedule 01.06.2015
comment
Не намирам файл на моя сървър   -  person PGSolutions SyGED    schedule 01.06.2015
comment
Filedatastore съхранява файла в %appdata% проверили ли сте там?   -  person DaImTo    schedule 01.06.2015
comment
Не виждам никакъв файл в AppData   -  person PGSolutions SyGED    schedule 01.06.2015
comment
Намерих най-накрая. Благодаря   -  person PGSolutions SyGED    schedule 01.06.2015


Отговори (1)


Можете да отмените токена, като се обадите на https://accounts.google.com/o/oauth2/revoke?token={токен}

Прочетете https://developers.google.com/identity/protocols/OAuth2WebServer

person ND003    schedule 03.07.2015