Как отозвать токен для пользователя

Как я могу отозвать токен для пользователя?

Это мой код аутентификации, и я хочу сбросить (отозвать) доступ для одного пользователя. Это связано с тем, что я использую 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
Вы пытались просто удалить файл для идентификатора пользователя?   -  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