use of com.dropbox.core.DbxPKCEWebAuth in project dropbox-sdk-java by dropbox.
the class PkceAuthorize method authorize.
public DbxAuthFinish authorize(DbxAppInfo appInfo) throws IOException {
// Run through Dropbox API authorization process without client secret
DbxRequestConfig requestConfig = new DbxRequestConfig("examples-authorize");
DbxAppInfo appInfoWithoutSecret = new DbxAppInfo(appInfo.getKey());
DbxPKCEWebAuth pkceWebAuth = new DbxPKCEWebAuth(requestConfig, appInfoWithoutSecret);
DbxWebAuth.Request webAuthRequest = DbxWebAuth.newRequestBuilder().withNoRedirect().withTokenAccessType(TokenAccessType.OFFLINE).build();
String authorizeUrl = pkceWebAuth.authorize(webAuthRequest);
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.");
System.out.print("Enter the authorization code here: ");
String code = new BufferedReader(new InputStreamReader(System.in)).readLine();
if (code == null) {
System.exit(1);
}
code = code.trim();
try {
// exchange.
return pkceWebAuth.finishFromCode(code);
} catch (DbxException ex) {
System.err.println("Error in DbxWebAuth.authorize: " + ex.getMessage());
System.exit(1);
return null;
}
}
Aggregations