Admin SDK / Email Settings API が最近変更されたかどうか知っている人はいますか? 以前は、無効になっているユーザーのユーザー アカウントを委任できましたが、現在はそうではありません。
以下はスタックトレースです。
400 Bad Request
{
"error" : "invalid_grant"
}. Stacktrace follows:
com.google.api.client.auth.oauth2.TokenResponseException: 400 Bad Request
{
"error" : "invalid_grant"
}
at com.google.api.client.auth.oauth2.TokenResponseException.from(TokenResponseException.java:105)
at com.google.api.client.auth.oauth2.TokenRequest.executeUnparsed(TokenRequest.java:287)
at com.google.api.client.auth.oauth2.TokenRequest.execute(TokenRequest.java:307)
at com.google.api.client.googleapis.auth.oauth2.GoogleCredential.executeRefreshToken(GoogleCredential.java:269)
at com.google.api.client.auth.oauth2.Credential.refreshToken(Credential.java:489)
at com.google.gdata.client.GoogleAuthTokenFactory$OAuth2Token.refreshToken(GoogleAuthTokenFactory.java:258)
at com.google.gdata.client.GoogleAuthTokenFactory.handleSessionExpiredException(GoogleAuthTokenFactory.java:702)
at com.google.gdata.client.GoogleService.handleSessionExpiredException(GoogleService.java:738)
at com.google.gdata.client.GoogleService.insert(GoogleService.java:617)
at com.google.gdata.client.appsforyourdomain.AppsForYourDomainService.insert(AppsForYourDomainService.java:100)
at sample.appsforyourdomain.gmailsettings.OpenDevGmailSettingsService.insertSettings(OpenDevGmailSettingsService.java:182)
at sample.appsforyourdomain.gmailsettings.OpenDevGmailSettingsService.addEmailDelegate(OpenDevGmailSettingsService.java:1073)
at com.opendev.core.GoogleEmailDelegateService.addEmailDelegate(GoogleEmailDelegateService.groovy:76)
at com.opendev.core.EmailDelegateController$_save_closure2_closure3.doCall(EmailDelegateController.groovy:68)
at com.opendev.core.EmailDelegateController$_save_closure2.doCall(EmailDelegateController.groovy:63)
at com.opendev.core.EmailDelegateController.save(EmailDelegateController.groovy:62)
at grails.plugin.multitenant.core.servlet.CurrentTenantServletFilter.doFilter(CurrentTenantServletFilter.java:53)
at grails.plugin.springsecurity.web.filter.GrailsAnonymousAuthenticationFilter.doFilter(GrailsAnonymousAuthenticationFilter.java:53)
at grails.plugin.springsecurity.web.authentication.RequestHolderAuthenticationFilter.doFilter(RequestHolderAuthenticationFilter.java:49)
at grails.plugin.springsecurity.web.authentication.logout.MutableLogoutFilter.doFilter(MutableLogoutFilter.java:82)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1146)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
at java.lang.Thread.run(Thread.java:701)
GmailSettingsService を更新し、新しいコンストラクターで OpenDevGmailSettingsService を作成しました。
public OpenDevGmailSettingsService(String domain, String serviceAccountId, String serviceAccountUser, String serviceAccountApplicationName, String privateKeyFileLocation) throws AuthenticationException {
super(serviceAccountApplicationName, Constants.PROTOCOL, Constants.APPS_APIS_DOMAIN);
this.domain = domain;
new GenericFeed().declareExtensions(getExtensionProfile());
try {
HttpTransport httpTransport = new NetHttpTransport();
JsonFactory JSON_FACTORY = JacksonFactory.getDefaultInstance();
List<String> SCOPES = Arrays
.asList("https://apps-apis.google.com/a/feeds/emailsettings/2.0/");
GoogleCredential credential = new GoogleCredential.Builder()
.setTransport(httpTransport)
.setJsonFactory(JSON_FACTORY)
.setServiceAccountId(serviceAccountId)
.setServiceAccountUser(serviceAccountUser)
.setServiceAccountScopes(SCOPES)
.setServiceAccountPrivateKeyFromP12File(
new File(privateKeyFileLocation)).build();
this.setOAuth2Credentials(credential);
} catch (Exception e) {
throw new AuthenticationException(
"Unable to initialize Gmail Settings service" + e);
}
}
これserviceAccountUser
は、現在のユーザーのドメインの admin-user-email-id です。