I have a java cron job that needs permanent access to a google storage bucket. All of the documentation I've seen require OAUTH user login for that. I've read about the refresh tokens, are there any code samples that show specifically how to get a permanent access token for a given cron job?
我有一个java cron作业,需要永久访问谷歌存储桶。我见过的所有文档都需要OAUTH用户登录。我已经阅读了有关刷新令牌的信息,是否有任何代码示例明确显示如何获取给定cron作业的永久访问令牌?
thanks
1 个解决方案
#1
0
Google Cloud Storage supports both OAuth 2.0 and access key/secret key authentication (details here). A simple way to solve your problem would be to write an application using a Java library (e.g. Jets3t) that makes it easy to upload files using a configured set of authentication credentials. You could then invoke your Java app from a cron job.
Google云端存储支持OAuth 2.0和访问密钥/密钥身份验证(详情请参见此处)。解决问题的一种简单方法是使用Java库(例如Jets3t)编写应用程序,以便使用一组配置的身份验证凭据轻松上载文件。然后,您可以从cron作业调用Java应用程序。
Note that a refresh token is valid until revoked, so once you have a valid refresh token, your cron job can use it to obtain access tokens (which are short-lived) indefinitely, without needing to use the web flow again.
请注意,刷新令牌在被撤销之前是有效的,因此一旦您拥有有效的刷新令牌,您的cron作业就可以无限期地使用它来获取访问令牌(这是短暂的),而无需再次使用Web流。
Even simpler, you could use the gsutil command in a cron job, which can also perform uploads based on stored credentials without requiring human intervention. If you go that route, be sure to set the BOTO_CONFIG environment variable so that the cron job can find your .boto file containing your stored authentication credentials and other configuration settings.
更简单的是,您可以在cron作业中使用gsutil命令,该命令还可以根据存储的凭据执行上载,而无需人工干预。如果您走这条路线,请务必设置BOTO_CONFIG环境变量,以便cron作业可以找到包含存储的身份验证凭据和其他配置设置的.boto文件。
#1
0
Google Cloud Storage supports both OAuth 2.0 and access key/secret key authentication (details here). A simple way to solve your problem would be to write an application using a Java library (e.g. Jets3t) that makes it easy to upload files using a configured set of authentication credentials. You could then invoke your Java app from a cron job.
Google云端存储支持OAuth 2.0和访问密钥/密钥身份验证(详情请参见此处)。解决问题的一种简单方法是使用Java库(例如Jets3t)编写应用程序,以便使用一组配置的身份验证凭据轻松上载文件。然后,您可以从cron作业调用Java应用程序。
Note that a refresh token is valid until revoked, so once you have a valid refresh token, your cron job can use it to obtain access tokens (which are short-lived) indefinitely, without needing to use the web flow again.
请注意,刷新令牌在被撤销之前是有效的,因此一旦您拥有有效的刷新令牌,您的cron作业就可以无限期地使用它来获取访问令牌(这是短暂的),而无需再次使用Web流。
Even simpler, you could use the gsutil command in a cron job, which can also perform uploads based on stored credentials without requiring human intervention. If you go that route, be sure to set the BOTO_CONFIG environment variable so that the cron job can find your .boto file containing your stored authentication credentials and other configuration settings.
更简单的是,您可以在cron作业中使用gsutil命令,该命令还可以根据存储的凭据执行上载,而无需人工干预。如果您走这条路线,请务必设置BOTO_CONFIG环境变量,以便cron作业可以找到包含存储的身份验证凭据和其他配置设置的.boto文件。