Unable to delegate users using Email Settings API

自闭症网瘾萝莉.ら 提交于 2020-01-07 03:05:32

问题


Does anyone know if the Admin SDK / Email Settings API has changed recently? Previously we were able to delegate a user account for a user that was disabled, this is no longer that case.

Following is the stacktrace:

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)

I update GmailSettingsService and created OpenDevGmailSettingsService with a new constructor:

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);
    }
}

Here serviceAccountUser is the admin-user-email-id of current user's domain.

来源:https://stackoverflow.com/questions/33293812/unable-to-delegate-users-using-email-settings-api

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!