After reading the documentation to implement the Dropbox library in my project, I want the user, when confirming the authorization through the browser, his Access Token is passed directly to the app, without the user making copy/paste of the code. The documentation is unclear on how to use HttpServletRequest
and HttpSession
and therefore I get this error.
public class DropboxGenerateToken {
public static DbxAuthFinish authFinish;
public static DbxAppInfo appInfo;
public static DbxAuthInfo authInfo;
public static DbxRequestConfig config;
public static String ACCESS_TOKEN = "";
public static void main(String args[]) throws DbxException, FileNotFoundException, IOException {
String accessToken = "";
String userLocale = null;
// Select a spot in the session for DbxWebAuth to store the CSRF token.
HttpServletRequest request = null;
HttpSession session = request.getSession(true);
String sessionKey = "dropbox-auth-csrf-token";
DbxSessionStore csrfTokenStore = new DbxStandardSessionStore(session, sessionKey);
String redirectUri = "http://my-server.com/dropbox-auth-finish";
DbxRequestConfig requestConfig = new DbxRequestConfig("text-edit/0.1", userLocale);
DbxAppInfo appInfo = new DbxAppInfo("mycode", "mycode");
DbxWebAuth auth = new DbxWebAuth(requestConfig, appInfo);
// Build an auth request
DbxWebAuth.Request authRequest = DbxWebAuth.newRequestBuilder()
.withRedirectUri(redirectUri, csrfTokenStore)
.build();
String authorizeUrl = auth.authorize(authRequest);
System.out.println("1. Go to " + authorizeUrl);
System.out.println("2. Click \"Allow\" (you might have to log in first).");
System.out.println("3. Copy the authorization code.");
try {
URL authenticationURL = new URL(authorizeUrl);
Desktop.getDesktop().browse(authenticationURL.toURI());
} catch (Exception e) {
// TODO Auto-generated catch block
}
String code = JOptionPane.showInputDialog(DropboxGenerateToken.class, "Inserta el codigo de verificación.");
System.out.println(code);
code = code.trim();
try {
DbxAuthFinish authFinish = auth.finishFromCode(code);
accessToken = authFinish.getAccessToken();
} catch (Exception e) {
}
}}
this is the error
Exception in thread "main" java.lang.NullPointerException
at login.DropboxGenerateToken.main(DropboxGenerateToken.java:61)
this line:HttpSession session = request.getSession(true);