public Credential loadCredential(String userId) { try { return createCodeFlow().loadCredential(userId); } catch (IOException e) { logger.error("Could not load credential", e); return null; } }
public static Credential getCredential(String userId) throws IOException { if (userId == null) { return null; } else { return AuthUtil.newAuthorizationCodeFlow().loadCredential(userId); } }
/** * Loads the Credential for the user from the underlying {@link DataStore}. * @throws AuthException If the credential could not be loaded. */ public Credential loadCredential(String userId) throws AuthException { try { return authorizationCodeFlow.loadCredential(userId); } catch (IOException e) { throw new AuthException("Unable to load credential.", e); } }
@Override public Credential loadCredential(String userId) throws IOException { return new OneDriveCredential(super.loadCredential(userId), businessResource); }
@Override public boolean credentialExists(final SessionInfo sessionInfo) { try { final AuthorizationCodeFlow flow = createFlow(transport); return (flow.loadCredential(sessionInfo.getUsername()) != null); } catch (final Exception ex) { throw new IllegalStateException("Failed reading Google credentials.", ex); } }
@Override public boolean credentialExists(final SessionInfo sessionInfo) { try { final AuthorizationCodeFlow flow = createFlow(transport); return (flow.loadCredential(sessionInfo.getUsername()) != null); } catch (final Exception ex) { throw new IllegalStateException("Failed reading Google credentials.", ex); } }
public static Credential getCredential(HttpServletRequest req) throws IOException { return AuthUtil.newAuthorizationCodeFlow().loadCredential(getUserId(req)); }
/** * Invalidate OAuth token for specified user. * * @param userId user * @return <code>true</code> if OAuth token invalidated and <code>false</code> otherwise, e.g. if * user does not have token yet */ public boolean invalidateToken(String userId) throws IOException { Credential credential = flow.loadCredential(userId); if (credential != null) { flow.getCredentialDataStore().delete(userId); return true; } return false; }
// Create the flow AuthorizationCodeFlow authorizationCodeFlow = new GoogleAuthorizationCodeFlow.Builder( new UrlFetchTransport(), new JacksonFactory(), CLIENT_ID, CLIENT_SECRET, Collections.singleton(OAUTH_SCOPES)) .setAccessType("offline") .setCredentialStore(new AppEngineCredentialStore()) .build(); // User Id: e.g. from session Credential credential = authorizationCodeFlow.loadCredential(USER_ID); // Make your API call. This example uses the Google+ API // If the access token has expired, it will automatically refresh Plus plus = new Plus(new UrlFetchTransport(), new JacksonFactory(), credential) .activities().list("me", "public").execute();
/** * Load a credential from the token store with the userId returned by getServiceUser() as key. */ @Override public Credential loadCredential(String user) { String userId = getServiceUserId(user); try { return userId != null ? getAuthorizationCodeFlow().loadCredential(userId) : null; } catch (IOException e) { throw new NuxeoException("Failed to load credential for " + user, e); } }
throw new IOException(AUTHENTICATOR_IS_NOT_CONFIGURED); Credential credential = flow.loadCredential(userId); if (credential == null) { return null; credential = flow.loadCredential(userId); } else {
flow = initializeFlow(); credential = flow.loadCredential(userId);
Credential credential = AuthUtil.newAuthorizationCodeFlow().loadCredential(userId); String message = "";
Credential credential = AuthUtil.newAuthorizationCodeFlow().loadCredential(userId);
/** * Authorizes the installed application to access user's protected data. * * @param userId user ID or {@code null} if not using a persisted credential store * @return credential */ public Credential authorize(String userId) throws IOException { try { Credential credential = flow.loadCredential(userId); if (credential != null && (credential.getRefreshToken() != null || credential.getExpiresInSeconds() == null || credential.getExpiresInSeconds() > 60)) { return credential; } // open in browser String redirectUri = receiver.getRedirectUri(); AuthorizationCodeRequestUrl authorizationUrl = flow.newAuthorizationUrl().setRedirectUri(redirectUri); onAuthorization(authorizationUrl); // receive authorization code and exchange it for an access token String code = receiver.waitForCode(); TokenResponse response = flow.newTokenRequest(code).setRedirectUri(redirectUri).execute(); // store credential and return it return flow.createAndStoreCredential(response, userId); } finally { receiver.stop(); } }