public void getTokenCredentials(LocalUserDetail user) throws FitbitAPIException { // Get cached resource credentials: APIResourceCredentials resourceCredentials = getResourceCredentialsByUser(user); if (resourceCredentials == null) { throw new FitbitAPIException( "User " + user.getUserId() + " does not have resource credentials. Need to grant authorization first."); } String tempToken = resourceCredentials.getTempToken(); String tempTokenSecret = resourceCredentials.getTempTokenSecret(); if (tempToken == null || tempTokenSecret == null) { throw new FitbitAPIException( "Resource credentials for resource " + user.getUserId() + " are in an invalid state: temporary token or secret is null."); } // Get and save token credentials: AccessToken accessToken = client.getOAuthAccessToken( tempToken, tempTokenSecret, resourceCredentials.getTempTokenVerifier()); resourceCredentials.setAccessToken(accessToken.getToken()); resourceCredentials.setAccessTokenSecret(accessToken.getTokenSecret()); resourceCredentials.setResourceId(accessToken.getEncodedUserId()); }
public Object getFromCache( LocalUserDetail user, APIResourceCredentials credentials, String cacheKey) { if (null != subscriptionStore && null != subscriptionStore.getBySubscriptionId(user.getUserId()) && null != entityCache) { return entityCache.get(credentials, cacheKey); } else { return null; } }
public String getResourceOwnerAuthorizationURL(LocalUserDetail user, String callbackURL) throws FitbitAPIException { // Get temporary credentials. Include callback URL which the Fitbit API service will save and // redirect to when // the user authorizes. TempCredentials tempCredentials = client.getOAuthTempToken(callbackURL); // Create and save temporary resource credentials: APIResourceCredentials resourceCredentials = new APIResourceCredentials( user.getUserId(), tempCredentials.getToken(), tempCredentials.getTokenSecret()); saveResourceCredentials(user, resourceCredentials); // Return Fitbit URL to redirect to where the user can authorize: return tempCredentials.getAuthorizationURL(); }
/** * Removes subscription * * @param collectionType * @param subscriptionId */ public void unsubscribe( String subscriberId, LocalUserDetail user, APICollectionType collectionType, final String subscriptionId) throws FitbitAPIException { if (null == subscriptionStore) { throw new FitbitAPIException( "Can not deal with subscriptions without a place to store information about them."); } // This example application only allows a single subscription per // (local) user. We use the user's ID as the subscription ID to avoid // having to maintain a mapping. client.unsubscribe( subscriberId, user, FitbitUser.CURRENT_AUTHORIZED_USER, collectionType, subscriptionId); LocalSubscriptionDetail subscription = subscriptionStore.getBySubscriptionId(user.getUserId()); if (null != subscription) { subscriptionStore.delete(subscription); } }