lib/drive_env/cli/spreadsheet.rb in drive_env-0.3.1 vs lib/drive_env/cli/spreadsheet.rb in drive_env-0.4.0
- old
+ new
@@ -73,18 +73,24 @@
DriveEnv.authorizer(config.client_id, config.client_secret, DriveEnv::Config::DEFAULT_TOKENS_STORE_FILE)
end
def credential
unless @credential
- @credential = authorizer.get_credentials(DriveEnv::Config::DEFAULT_TOKEN_USER_ID)
- case
- when @credential.nil?
- abort "please set access_token: #{$0} auth login"
- when @credential.expired?
+ case authorizer
+ when Google::Auth::UserAuthorizer
+ @credential = authorizer.get_credentials(DriveEnv::Config::DEFAULT_TOKEN_USER_ID)
+ case
+ when @credential.nil?
+ abort "please set access_token: #{$0} auth login"
+ when @credential.expired?
+ @credential.fetch_access_token!
+ @credential.expires_at = credential.issued_at + credential.expires_in
+ authorizer.store_credentials(DriveEnv::Config::DEFAULT_TOKEN_USER_ID, @credential)
+ end
+ when Google::Auth::ServiceAccountCredentials
+ @credential = authorizer
@credential.fetch_access_token!
- @credential.expires_at = credential.issued_at + credential.expires_in
- authorizer.store_credentials(DriveEnv::Config::DEFAULT_TOKEN_USER_ID, @credential)
end
end
@credential
end
@@ -132,6 +138,5 @@
end
end
end
end
end
-