/** * Returns an HttpRequestFactory object that has been signed with the active user's authentication * headers to use to make http requests. If the user has not signed in, this method will block and * pop up the login dialog to the user. If the user cancels signing in, this method will return * null. * * <p>If the access token that was used to sign this transport was revoked or has expired, then * execute() invoked on Request objects constructed from this transport will throw an exception, * for example, "com.google.api.client.http.HttpResponseException: 401 Unauthorized" * * @return An HttpRequestFactory object that has been signed with the active user's authentication * headers or null if there is no active user. */ @Nullable public HttpRequestFactory createRequestFactory() { return createRequestFactory(null); }
@NotNull @Override public Optional<CredentialedUser> getLoggedInUser(String username) { return Optional.ofNullable(getAllUsers().get(username)); }
@Override public void logInIfNot() { if (!isLoggedIn()) { logIn(); } }
@Override public boolean ensureLoggedIn(String username) { Optional<CredentialedUser> projectUser = getLoggedInUser(username); while (!projectUser.isPresent()) { int addUserResult = Messages.showOkCancelDialog( AccountMessageBundle.message("login.credentials.missing.message", username), AccountMessageBundle.message("login.credentials.missing.dialog.title"), AccountMessageBundle.message("login.credentials.missing.dialog.addaccount.button"), AccountMessageBundle.message("login.credentials.missing.dialog.cancel.button"), Messages.getWarningIcon()); if (addUserResult == Messages.OK) { logIn(); projectUser = getLoggedInUser(username); } else { return false; } } return true; }
users.removeActiveUser(); final GoogleLoginState state = createGoogleLoginState(false); getCurrentProject(), AccountMessageBundle.message("login.service.sign.in.via.browser.modal.text"), true) {
@Override public void logIn() { logIn(null, null); }
private void restoreLastActiveUser() { if (lastActiveUser != null) { setActiveUser(lastActiveUser.getEmail()); } } }.queue();
private IntegratedIntellijGoogleLoginService() { this.clientInfo = getClientInfo(); this.uiFacade = new AndroidUiFacade(); this.users = new CredentialedUserRoster(); this.dataStore = new AndroidPreferencesOAuthDataStore(); }
@Override public boolean logOut(boolean showPrompt) { CredentialedUser activeUser = users.getActiveUser(); if (activeUser == null) { return false; } boolean loggedOut = activeUser.getGoogleLoginState().logOut(showPrompt); if (loggedOut) { logOutAllUsers(); UsageTrackerService.getInstance().trackEvent(LoginTracking.LOGOUT_COMPLETE).ping(); } return loggedOut; }