Search in sources :

Example 1 with Oauth2

use of com.google.api.services.oauth2.Oauth2 in project google-cloud-intellij by GoogleCloudPlatform.

the class GoogleLoginUtils method getUserInfo.

/**
 * Sets the user info on the callback.
 */
@SuppressWarnings("FutureReturnValueIgnored")
public static void getUserInfo(@NotNull final Credential credential, final IUserPropertyCallback<Userinfoplus> callback) {
    final Oauth2 userInfoService = new Oauth2.Builder(new NetHttpTransport(), new JacksonFactory(), credential).setApplicationName(ServiceManager.getService(PluginInfoService.class).getUserAgent()).build();
    ApplicationManager.getApplication().executeOnPooledThread(() -> {
        Userinfoplus userInfo = null;
        try {
            userInfo = userInfoService.userinfo().get().execute();
        } catch (IOException ex) {
            // The core IDE functionality still works, so this does
            // not affect anything right now. The user will receive
            // error messages when they attempt to do something that
            // requires a logged in state.
            LOG.warn("Error retrieving user information.", ex);
        }
        if (userInfo != null && userInfo.getId() != null) {
            callback.setProperty(userInfo);
        } else {
            callback.setProperty(null);
        }
    });
}
Also used : Userinfoplus(com.google.api.services.oauth2.model.Userinfoplus) NetHttpTransport(com.google.api.client.http.javanet.NetHttpTransport) Oauth2(com.google.api.services.oauth2.Oauth2) PluginInfoService(com.google.cloud.tools.intellij.service.PluginInfoService) IOException(java.io.IOException) JacksonFactory(com.google.api.client.json.jackson2.JacksonFactory)

Example 2 with Oauth2

use of com.google.api.services.oauth2.Oauth2 in project workbench by all-of-us.

the class UserInfoService method getUserInfo.

public Userinfoplus getUserInfo(String token) throws IOException {
    GoogleCredential credential = new GoogleCredential().setAccessToken(token);
    Oauth2 oauth2 = new Oauth2.Builder(httpTransport, jsonFactory, credential).setApplicationName(APPLICATION_NAME).build();
    return ExceptionUtils.executeWithRetries(oauth2.userinfo().get());
}
Also used : Oauth2(com.google.api.services.oauth2.Oauth2) GoogleCredential(com.google.api.client.googleapis.auth.oauth2.GoogleCredential)

Aggregations

Oauth2 (com.google.api.services.oauth2.Oauth2)2 GoogleCredential (com.google.api.client.googleapis.auth.oauth2.GoogleCredential)1 NetHttpTransport (com.google.api.client.http.javanet.NetHttpTransport)1 JacksonFactory (com.google.api.client.json.jackson2.JacksonFactory)1 Userinfoplus (com.google.api.services.oauth2.model.Userinfoplus)1 PluginInfoService (com.google.cloud.tools.intellij.service.PluginInfoService)1 IOException (java.io.IOException)1