Google驱动器OAuth2:TokenResponse文件的加密使用?

时间:2019-06-02 12:34:55

标签: encryption google-drive-api google-oauth2 bearer-token

是否可以加密使用Google驱动器OAuth2 TokenResponse文件?

我的目标:
如果我的令牌文件已加密,则最终用户无法将其(在浏览器中的权限之后)用于另一个目标。

谢谢!

VB.NET代码:

'prerequisites: create oauth2 client ids for gmail user and download file client_secret.json
Dim GooSvc As Google.Apis.Drive.v3.DriveService
Dim UserInfo As Google.Apis.Auth.OAuth2.UserCredential
Dim Stream1 = New System.IO.MemoryStream(New System.Text.UTF8Encoding().GetBytes("content_of_client_secret.json"))
UserInfo = Google.Apis.Auth.OAuth2.GoogleWebAuthorizationBroker.AuthorizeAsync(
    Google.Apis.Auth.OAuth2.GoogleClientSecrets.Load(Stream1).Secrets,
    New String() {"https://www.googleapis.com/auth/drive"},
    "user1",
    System.Threading.CancellationToken.None,
    New Google.Apis.Util.Store.FileDataStore("d:\temp", True)).Result
GooSvc = New Google.Apis.Drive.v3.DriveService(New Google.Apis.Services.BaseClientService.Initializer() With {.HttpClientInitializer = UserInfo})

此后,令牌文件d:\temp\Google.Apis.Auth.OAuth2.Responses.TokenResponse-user1
-如果不存在则自动创建(在浏览器中的权限之后)
-如果过期(1小时后)会自动刷新
-如果是“新鲜”(在1小时内),则没有任何反应

令牌文件的示例内容:

{"access_token":"ya29.XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX-XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX","token_type":"Bearer","expires_in":3600,"refresh_token":"1/XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX","scope":"https://www.googleapis.com/auth/drive","Issued":"2019-06-02T13:21:54.775+02:00","IssuedUtc":"2019-06-02T11:21:54.775Z"}

0 个答案:

没有答案