无法生成离线Oauth2.0 access_token

时间:2020-03-11 02:27:18

标签: api oauth-2.0

我需要调用Google的自定义API,因此需要Oauth的身份验证才能调用它。但是,当我将access_type设置为offline时,Google并未将refresh_token返回给我。因此,我的access_token将在一个小时后过期,并且不会自动刷新。这是我生成的代码:

List<String> array = new ArrayList<>();
array.add("https://www.googleapis.com/auth/androidworkzerotouchemm");
InputStream in = CustomerQuickstart.class.getResourceAsStream("/9443.json");
GoogleClientSecrets clientSecrets = GoogleClientSecrets.load(JacksonFactory.getDefaultInstance(), new InputStreamReader(in, "UTF-8"));
GoogleAuthorizationCodeFlow flow = new GoogleAuthorizationCodeFlow.Builder(
                GoogleNetHttpTransport.newTrustedTransport(), JacksonFactory.getDefaultInstance(), clientSecrets, array)
                .setDataStoreFactory(new FileDataStoreFactory(new java.io.File(
                        System.getProperty("user.home"), ".9443/zero-touch.quickstart.json")))
                .setAccessType("offline")
                .build(); 
Credential credential = new AuthorizationCodeInstalledApp(
                flow, new CodeReceiver("https://xxxxxxx.com/dacc/manager/device/zerotouch/active")).authorize("userId");

凭据中没有refresh_token access_token

0 个答案:

没有答案