public static Auth getAuth(AuthData authData, Flickr flickr) throws FlickrException { checkArgument( authData instanceof TokenSecretAuthData, "authData expected to be TokenSecretAuthData not %s", authData.getClass().getCanonicalName()); TokenSecretAuthData tokenAuthData = (TokenSecretAuthData) authData; Token requestToken = new Token(tokenAuthData.getToken(), tokenAuthData.getSecret()); return flickr.getAuthInterface().checkToken(requestToken); } }
photoSetList = photosetsInterface.getList( auth.getUser().getId(), PHOTO_SETS_PER_PAGE, page, PHOTOSET_EXTRAS); } catch (FlickrException e) { return new ExportResult<>(e);
/** * Get the OAuth request token - this is step one of authorization. * * @return the {@link OAuth1RequestToken}, store this for when the user returns from the Flickr website. */ public OAuth1RequestToken getRequestToken() { return getRequestToken(null); }
/** * * @param response * @param tokenSecret * @param authToken */ private Auth constructAuth(Response response, String authToken, String tokenSecret) { Auth auth = new Auth(); Element authElement = response.getPayload(); auth.setToken(authToken); auth.setTokenSecret(tokenSecret); auth.setPermission(Permission.fromString(XMLUtilities.getChildValue(authElement, "perms"))); Element userElement = XMLUtilities.getChild(authElement, "user"); User user = new User(); user.setId(userElement.getAttribute("nsid")); user.setUsername(userElement.getAttribute("username")); user.setRealName(userElement.getAttribute("fullname")); auth.setUser(user); return auth; }
public static void main(String[] args) throws Exception { FileAuthStore fas = new FileAuthStore(new File(System.getProperty("user.home") + File.separatorChar + "flickrauth")); Auth a = new Auth(); User u = new User(); u.setId("THISISMYNSID"); a.setUser(u); fas.store(a); fas = null; fas = new FileAuthStore(new File(System.getProperty("user.home") + File.separatorChar + "flickrauth")); Auth a2 = fas.retrieve("THISISMYNSID"); System.out.println(a2.getUser().getId()); } }
/** * Get the AuthInterface. * * @return The AuthInterface */ @Override public AuthInterface getAuthInterface() { if (authInterface == null) { authInterface = new AuthInterface(apiKey, sharedSecret, transport); } return authInterface; }
/** * Get the auth URL, this is step two of authorization. * * @param oAuthRequestToken * the token from a {@link AuthInterface#getRequestToken} call. */ public String getAuthorizationUrl(OAuth1RequestToken oAuthRequestToken, Permission permission) { OAuth10aService service = new ServiceBuilder(apiKey) .apiSecret(sharedSecret) .build(FlickrApi.instance()); String authorizationUrl = service.getAuthorizationUrl(oAuthRequestToken); return String.format("%s&perms=%s", authorizationUrl, permission.toString()); }
/** * * @param response * @param tokenSecret * @param authToken */ private Auth constructAuth(Response response, String authToken, String tokenSecret) { Auth auth = new Auth(); Element authElement = response.getPayload(); auth.setToken(authToken); auth.setTokenSecret(tokenSecret); auth.setPermission(Permission.fromString(XMLUtilities.getChildValue(authElement, "perms"))); Element userElement = XMLUtilities.getChild(authElement, "user"); User user = new User(); user.setId(userElement.getAttribute("nsid")); user.setUsername(userElement.getAttribute("username")); user.setRealName(userElement.getAttribute("fullname")); auth.setUser(user); return auth; }
when(authInterface.checkToken(any(Token.class))).thenReturn(auth);
public void clear(String nsid) { Auth a = this.auths.get(nsid); if(a != null) { this.authsByUser.remove(a.getUser().getUsername()); } this.auths.remove(nsid); this.authsByUser.remove(nsid); // in case username is passed. File auth = new File(this.authStoreDir, nsid + ".auth"); if (auth.exists()) auth.delete(); }
/** * Get the OAuth request token - this is step one of authorization. * * @return the {@link Token}, store this for when the user returns from the Flickr website. */ public Token getRequestToken() { return getRequestToken(null); }
/** * Get the AuthInterface. * * @return The AuthInterface */ @Override public AuthInterface getAuthInterface() { if (authInterface == null) { authInterface = new AuthInterface(apiKey, sharedSecret, transport); } return authInterface; }
/** * Get the auth URL, this is step two of authorization. * * @param oAuthRequestToken * the token from a {@link AuthInterface#getRequestToken} call. */ public String getAuthorizationUrl(Token oAuthRequestToken, Permission permission) { OAuthService service = new ServiceBuilder().provider(FlickrApi.class).apiKey(apiKey).apiSecret(sharedSecret).build(); String authorizationUrl = service.getAuthorizationUrl(oAuthRequestToken); return String.format("%s&perms=%s", authorizationUrl, permission.toString()); }
when(authInterface.checkToken(any(Token.class))).thenReturn(auth); when(flickr.getPhotosetsInterface()).thenReturn(photosetsInterface); when(flickr.getPhotosInterface()).thenReturn(photosInterface);
public void clear(String nsid) { Auth a = this.auths.get(nsid); if(a != null) { this.authsByUser.remove(a.getUser().getUsername()); } this.auths.remove(nsid); this.authsByUser.remove(nsid); // in case username is passed. File auth = new File(this.authStoreDir, nsid + ".auth"); if (auth.exists()) auth.delete(); }
when(authInterface.checkToken(any(Token.class))).thenReturn(auth); when(flickr.getPhotosetsInterface()).thenReturn(photosetsInterface); when(flickr.getPhotosInterface()).thenReturn(photosInterface);
public void store(Auth token) throws IOException { this.auths.put(token.getUser().getId(), token); this.authsByUser.put(token.getUser().getUsername(), token); String filename = token.getUser().getId() + ".auth"; File outFile = new File(this.authStoreDir, filename); outFile.createNewFile(); ObjectOutputStream authStream = new ObjectOutputStream(new FileOutputStream(outFile)); authStream.writeObject(token); authStream.flush(); authStream.close(); }
/** * Returns the credentials attached to an OAuth authentication token. * * @param accessToken * The authentication token * @return The Auth object * @throws FlickrException */ public Auth checkToken(OAuth1Token accessToken) throws FlickrException { return checkToken(accessToken.getToken(), accessToken.getTokenSecret()); }
public void store(Auth token) throws IOException { this.auths.put(token.getUser().getId(), token); this.authsByUser.put(token.getUser().getUsername(), token); String filename = token.getUser().getId() + ".auth"; File outFile = new File(this.authStoreDir, filename); outFile.createNewFile(); ObjectOutputStream authStream = new ObjectOutputStream(new FileOutputStream(outFile)); authStream.writeObject(token); authStream.flush(); authStream.close(); }
/** * Returns the credentials attached to an OAuth authentication token. * * @param accessToken * The authentication token * @return The Auth object * @throws FlickrException */ public Auth checkToken(Token accessToken) throws FlickrException { return checkToken(accessToken.getToken(), accessToken.getSecret()); }