Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
114 commits
Select commit Hold shift + click to select a range
df6ad00
Fix logging placeholder mismatch
koppor Dec 1, 2025
5cd62ca
Remove wrong empty line
koppor Dec 1, 2025
801d18e
Fix wrong space
koppor Dec 1, 2025
c03e269
Route prefernces through
koppor Dec 1, 2025
cd79986
Use OneConstant instead of Factor for preferences
koppor Dec 1, 2025
fdf7e01
Remove obsolete file
koppor Dec 1, 2025
809371a
First OAuth2 flow
koppor Dec 1, 2025
0d60e9f
Magic merge commit for PR #14489
koppor Dec 1, 2025
79397c5
Merge into add-oauth2
koppor Dec 1, 2025
1cd243b
Change scope to make lib happy
koppor Dec 1, 2025
05df76e
Add initial check for token
koppor Dec 1, 2025
94a614c
Fix checkstyle
koppor Dec 1, 2025
08b15ce
Fix formatting
koppor Dec 1, 2025
1de39fb
Try to fix JBang
koppor Dec 1, 2025
fce7891
Merge branch 'main' into add-oauth2
koppor Dec 10, 2025
d5bb396
Add final
koppor Dec 10, 2025
43850df
Merge remote-tracking branch 'origin/main' into add-oauth2
koppor Dec 12, 2025
8f70267
Fix scope
koppor Dec 12, 2025
fa45b4d
Fix typo
koppor Dec 12, 2025
f12cd44
Fix checkstyle
koppor Dec 12, 2025
77bc336
Try to group resources classes under "resources"
koppor Dec 12, 2025
0ee36b6
"manager" belongs to http.server, not general http
koppor Dec 12, 2025
595e8a3
Ignore gcl.mv
koppor Dec 12, 2025
317d84c
Rename "callback" resource - and start to work on OAuthSessionRegistry
koppor Dec 12, 2025
b7e699f
Outputting error_description
koppor Dec 12, 2025
e9ba682
Browser should show error
koppor Dec 12, 2025
2a5b39c
Add challenge
koppor Dec 12, 2025
c5c487a
Remove OpenId requirement
koppor Dec 12, 2025
1662407
Remove scope and introduce variables for debuggin
koppor Dec 12, 2025
06a707a
Add trace statement
koppor Dec 12, 2025
600e7ae
Merge remote-tracking branch 'origin/main' into add-oauth2
koppor Dec 12, 2025
3238357
Remove Scope
koppor Dec 12, 2025
133d5e2
Increase timeout
koppor Dec 12, 2025
23af6c9
Successful interaction
koppor Dec 12, 2025
416d6fa
Add MWE for PUT to CiteDrive
koppor Dec 12, 2025
3d7ea80
Fix path
koppor Dec 12, 2025
d440eb4
Add `@Disabled`
koppor Dec 12, 2025
2f057ab
add refresh token handling
Siedlerchr Dec 15, 2025
8be4070
WIP: Store in preferences
koppor Dec 15, 2025
e63991f
Merge branch 'main' into add-oauth2
koppor Dec 19, 2025
af7e603
Remove commented code
koppor Dec 19, 2025
e54be7d
Finish reading/writing token
koppor Dec 19, 2025
98f4ff7
Disable test
koppor Dec 19, 2025
b74c6a1
Add localization
koppor Dec 19, 2025
f923aac
Initial code for push
koppor Dec 19, 2025
3752bd1
Some more changes
koppor Dec 19, 2025
d7eaeb1
WIP
koppor Dec 19, 2025
d2870a2
Add link to run oauth2 mock server
koppor Dec 19, 2025
1d56729
Refine error message
koppor Dec 19, 2025
edac48b
Refined also in log
koppor Dec 19, 2025
9f5df7a
Fix architecture test vioalation
koppor Dec 20, 2025
d077ea8
Fix localization check
koppor Dec 20, 2025
aab3fdd
Merge branch 'main' into add-oauth2
koppor Dec 23, 2025
1292da7
Merge remote-tracking branch 'upstream/main' into add-oauth2
Siedlerchr May 5, 2026
1b75389
jban urls
Siedlerchr May 5, 2026
445101c
fix erroprs
Siedlerchr May 5, 2026
56efb6b
checsktyle
Siedlerchr May 5, 2026
e5a8bb4
Merge branch 'main' into add-oauth2
Siedlerchr May 11, 2026
25466ea
fix module info
Siedlerchr May 11, 2026
2865241
fix login and push to citedrive and refresh token hnadling
Siedlerchr May 11, 2026
0a5ff8e
checkstyle
Siedlerchr May 11, 2026
3460c51
fix jbang
Siedlerchr May 11, 2026
b3fa587
fix jbang
Siedlerchr May 11, 2026
136f1e2
add json smart
Siedlerchr May 11, 2026
84b0430
Merge branch 'main' into add-oauth2
koppor May 12, 2026
cb1cc61
Merge remote-tracking branch 'origin/main' into add-oauth2
koppor Aug 31, 2026
45b291c
Merge remote-tracking branch 'origin/main' into add-oauth2
koppor Aug 31, 2026
2395e27
Merge remote-tracking branch 'origin/main' into add-oauth2
koppor Sep 5, 2026
26b0eb2
Merge remote-tracking branch 'origin/main' into add-oauth2
koppor Sep 7, 2026
af0fd1f
Fix compilation after merge with main
koppor Sep 8, 2026
36fdacf
Merge remote-tracking branch 'origin/main' into add-oauth2
claude Sep 9, 2026
5dc1696
Merge remote-tracking branch 'origin/main' into add-oauth2
claude Sep 14, 2026
a9abccd
Merge remote-tracking branch 'origin/main' into add-oauth2
claude Sep 16, 2026
de157fb
Merge remote-tracking branch 'origin/main' into add-oauth2
koppor Sep 21, 2026
28c65ce
Fix HttpServerManager package after merge with main
koppor Sep 21, 2026
bc60458
Fix issues using OpenRewrite
github-actions[bot] Sep 21, 2026
621ea4b
Merge remote-tracking branch 'origin/main' into add-oauth2
koppor Sep 22, 2026
50dff06
Open CiteDrive import page after a successful push
koppor Sep 22, 2026
6870614
Add CHANGELOG entry for CiteDrive push
koppor Sep 22, 2026
4692b47
Make CiteDrive server URLs preferences
koppor Sep 22, 2026
744f87f
Fix architecture, localization and native-image test failures
koppor Sep 22, 2026
0e6cafd
Harden CiteDrive login and push
koppor Sep 22, 2026
ba6c035
Merge remote-tracking branch 'upstream/main' into add-oauth2
github-actions[bot] Sep 22, 2026
67ceeed
Push plain BibTeX to CiteDrive without touching the library
koppor Sep 22, 2026
a3ea87f
Merge remote-tracking branch 'origin/add-oauth2' into add-oauth2
koppor Sep 22, 2026
55cbf44
Merge remote-tracking branch 'origin/main' into add-oauth2
koppor Sep 23, 2026
54467e2
Open long login URLs on Windows and keep the stored login
koppor Sep 23, 2026
0d7caf7
Keep StandardActions order unchanged
koppor Sep 23, 2026
de7b854
Fix the push test on Windows
koppor Sep 23, 2026
a86423f
Offer to enable the HTTP server when logging in to CiteDrive
koppor Sep 23, 2026
a3e64c6
Say when the CiteDrive login page is being opened
koppor Sep 23, 2026
a0bb2b5
Show a proper page after the CiteDrive login
koppor Sep 23, 2026
cc391c2
Align the Javadoc parameter descriptions
koppor Sep 23, 2026
0cd6af1
Put Push to CiteDrive above Login
koppor Sep 23, 2026
1020e76
Add an External storages preferences tab
koppor Sep 23, 2026
722c408
Merge branch 'main' into add-oauth2
koppor Sep 28, 2026
a7ddbc8
Hide CiteDrive until it is enabled
koppor Sep 28, 2026
b86fe86
Merge remote-tracking branch 'origin/main' into add-oauth2
koppor Sep 30, 2026
6ea319a
Merge remote-tracking branch 'origin/main' into add-oauth2
claude Oct 1, 2026
64e29c2
Reset the CiteDrive addresses to their defaults
koppor Oct 1, 2026
21f5b06
Drop the reset test
koppor Oct 1, 2026
53b0b45
Update jablib/src/main/java/org/jabref/logic/net/CiteDrivePreferences…
Siedlerchr Oct 5, 2026
a927744
Merge remote-tracking branch 'origin/main' into add-oauth2
claude Oct 11, 2026
ce10bef
Merge remote-tracking branch 'upstream/main' into add-oauth2
github-actions[bot] Oct 11, 2026
9913c90
Address review: trim tests, tidy l10n and jbang deps
koppor Oct 12, 2026
d8f7818
Add jabsrv --citedrive-login
koppor Oct 12, 2026
f3d33e7
Merge remote-tracking branch 'origin/main' into add-oauth2
koppor Oct 12, 2026
42e98d6
Merge remote-tracking branch 'upstream/main' into add-oauth2
github-actions[bot] Oct 17, 2026
a32ad4b
Merge remote-tracking branch 'origin/main' into add-oauth2
koppor Oct 19, 2026
f8e65bc
Merge branch 'main' into add-oauth2
koppor Oct 19, 2026
f679eb5
fix(citedrive): secure OAuth token handling
Siedlerchr Oct 19, 2026
6f89c01
test(gui): make custom browser test portable
Siedlerchr Oct 19, 2026
59e25ce
style(citedrive): apply IntelliJ formatting
Siedlerchr Oct 19, 2026
011e240
docs: remove misplaced CiteDrive module details
Siedlerchr Oct 19, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 9 additions & 5 deletions .jbang/JabSrvLauncher.java
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@
//DEPS tools.jackson.core:jackson-core:3.2.4
//DEPS tools.jackson.core:jackson-databind:3.2.4
//DEPS tools.jackson.dataformat:jackson-dataformat-yaml:3.2.4
//DEPS com.nimbusds:oauth2-oidc-sdk:11.30.1
//DEPS net.minidev:json-smart:2.6.0

//SOURCES ../jabsrv/src/main/java/org/jabref/http/dto/BibEntryDTO.java
//SOURCES ../jabsrv/src/main/java/org/jabref/http/dto/cayw/SimpleJson.java
Expand Down Expand Up @@ -92,11 +94,12 @@
//SOURCES ../jabsrv/src/main/java/org/jabref/http/server/cayw/gui/SearchField.java
//SOURCES ../jabsrv/src/main/java/org/jabref/http/server/cayw/gui/SearchResultContainer.java
//SOURCES ../jabsrv/src/main/java/org/jabref/http/server/cayw/gui/SelectedItemsContainer.java
//SOURCES ../jabsrv/src/main/java/org/jabref/http/server/command/Command.java
//SOURCES ../jabsrv/src/main/java/org/jabref/http/server/command/CommandResource.java
//SOURCES ../jabsrv/src/main/java/org/jabref/http/server/command/FocusCommand.java
//SOURCES ../jabsrv/src/main/java/org/jabref/http/server/command/OpenLibrariesCommand.java
//SOURCES ../jabsrv/src/main/java/org/jabref/http/server/command/SelectEntriesCommand.java
//SOURCES ../jabsrv/src/main/java/org/jabref/http/server/resources/callback/CallbackResource.java
//SOURCES ../jabsrv/src/main/java/org/jabref/http/server/resources/command/Command.java
//SOURCES ../jabsrv/src/main/java/org/jabref/http/server/resources/command/FocusCommand.java
//SOURCES ../jabsrv/src/main/java/org/jabref/http/server/resources/command/OpenLibrariesCommand.java
//SOURCES ../jabsrv/src/main/java/org/jabref/http/server/resources/command/CommandResource.java
//SOURCES ../jabsrv/src/main/java/org/jabref/http/server/resources/command/SelectEntriesCommand.java
//SOURCES ../jabsrv/src/main/java/org/jabref/http/server/resources/CitationsResource.java
//SOURCES ../jabsrv/src/main/java/org/jabref/http/server/resources/LibrariesQueryResource.java
//SOURCES ../jabsrv/src/main/java/org/jabref/http/server/resources/LibrariesResource.java
Expand All @@ -114,6 +117,7 @@
// new jablib sources not yet in the 6.0-SNAPSHOT artifact
//SOURCES ../jablib/src/main/java/org/jabref/logic/importer/plaincitation/PlainCitationParserFactory.java
//SOURCES ../jablib/src/main/java/org/jabref/logic/UiCommand.java
//SOURCES ../jablib/src/main/java/org/jabref/logic/citedrive/OAuthSessionRegistry.java
//SOURCES ../jablib/src/main/java/org/jabref/logic/search/LibrarySearcher.java
//SOURCES ../jablib/src/main/java/org/jabref/logic/search/NoOpSearchBackend.java
//SOURCES ../jablib/src/main/java/org/jabref/logic/search/SearchBackend.java
Expand Down
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ Note that this project **does not** adhere to [Semantic Versioning](https://semv
- We added "Contribute to JabRef" to the Help menu, linking to [contribute.jabref.org](https://contribute.jabref.org). [#17162](https://github.com/JabRef/jabref/pull/17162)
- We added EasyOCR, PaddleOCR, and AppleOCR as selectable OCR engines, alongside Tesseract and Docling. [#16866](https://github.com/JabRef/jabref/issues/16866)
- We added syntax highlighting to the BibTeX source window of the citations tab. [#17355](https://github.com/JabRef/jabref/issues/17355)
- We added pushing the current library to [CiteDrive](https://www.citedrive.com/), including logging in to CiteDrive. [#14493](https://github.com/JabRef/jabref/pull/14493)

### Changed

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,31 @@ extraJavaModuleInfo {
uses("kong.unirest.core.json.JsonEngine")
}
module("com.konghq:unirest-modules-gson", "unirest.modules.gson")

// region nimbusdl
// required by nimbusdl
module("com.github.stephenc.jcip:jcip-annotations", "jcip.annotations") {
exportAllPackages()
}
module("net.minidev:json-smart", "json.smart") {
exportAllPackages()
}
module("com.nimbusds:content-type", "nimbusds.contenttype") {
overrideModuleName()
exportAllPackages()
}
knownModule("com.nimbusds:nimbus-jose-jwt", "com.nimbusds.jose.jwt")
module("com.nimbusds:lang-tag", "nimbusds.langtag") {
overrideModuleName()
exportAllPackages()
}
module("com.nimbusds:oauth2-oidc-sdk", "nimbusds.oauth2.oidc.sdk") {
overrideModuleName()
exportAllPackages()
requireAllDefinedDependencies()
}
// endregion

module("com.squareup.okhttp3:mockwebserver3", "mockwebserver3") {
preserveExisting()
}
Expand Down
27 changes: 27 additions & 0 deletions docs/code-howtos/http-server.md
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,33 @@ The library name `current` denotes the currently focussed library in JabRef.
./gradlew :jabsrv-cli:run --args="../jablib/src/test/resources/testbib/complex.bib"
```

## Logging in to CiteDrive without the GUI

`jabsrv --citedrive-login` prints the CiteDrive login address, waits for the browser to come back to `/callback`, stores the refresh token in the system keyring, and exits.
JabRef's HTTP server port from the preferences has to be the port `jabsrv` listens on, since CiteDrive redirects the browser there.

```shell
./gradlew :jabsrv-cli:run --args="--citedrive-login"
```

### CiteDrive authentication security

CiteDrive's API and web application addresses must use HTTPS; only the local browser callback uses HTTP.
Each authentication operation captures its server settings, and uploads use the address associated with their access token.
Changing the API address clears the login and prevents pending responses from restoring credentials for the previous configuration.
The keyring stores the API address alongside the refresh token; existing tokens without that binding require another login.

Concurrent token requests share one authentication operation to support refresh token rotation.
Both token exchange and refresh use a ten-second connection timeout and a thirty-second read timeout, with redirects disabled.
The code exchange runs asynchronously so that a slow token endpoint does not block the callback response.
Temporary errors preserve the stored login; an HTTP 400 `invalid_grant` response starts another browser login.

The current upload sends all entries from the active library in a single BibTeX request to `/jabref/push/`.
Each upload therefore uses one request from the endpoint's current allowance of 100 requests per hour per user; the server's payload size limit is a separate constraint.
`CiteDrivePushTest` verifies batches of two and one thousand entries by parsing the prepared request back into entries.
Setting the test JVM system property `citedrive.batch.fixture` to a generated 100,000-entry library adds that fixture to the same check.
The test records the payload size and preparation timings without contacting CiteDrive.

## Developing with IntelliJ

IntelliJ Ultimate offers a Markdown-based http-client. You need to open the file `jabsrv/src/test/rest-api.http`.
Expand Down
73 changes: 73 additions & 0 deletions docs/requirements/citedrive.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
---
parent: Requirements
---
# CiteDrive

## Log in to CiteDrive
`req~citedrive.login~1`

JabRef logs the user in to CiteDrive in the browser (OAuth 2.0 authorization code flow with PKCE).
The browser returns to JabRef's HTTP server; if it is disabled, JabRef asks the user to enable it and only then opens the browser.
`jabsrv --citedrive-login` offers the same login without the GUI: it prints the login address instead of opening the browser.
A login not completed within ten minutes fails.
The refresh token is stored in the system keyring only, never in the preferences.

Needs: impl, utest

## Push the library to CiteDrive
`req~citedrive.push~1`

"Push to CiteDrive" uploads the current library as BibTeX.
Without a valid refresh token, JabRef logs in first.
A network error while refreshing the token keeps the stored login.

Needs: impl, utest

## Open the import page after a push
`req~citedrive.push.import-page~1`

After a successful push, JabRef opens the CiteDrive page where the user chooses a project and the pushed entries to import.

Needs: impl

## CiteDrive credentials must remain bound to their server
`req~citedrive.credentials.server~1`

Changing the API address invalidates the saved login, including pending authentication responses.
Stored refresh tokens are loaded only for the address that issued them.
An upload uses the API address captured when its access token was requested.

Needs: impl, utest

## CiteDrive server addresses must use HTTPS
`req~citedrive.https~1`

The authorization, token, upload, and web application addresses must use HTTPS.
The browser callback remains on the local HTTP loopback listener.

Needs: impl, utest

## Concurrent CiteDrive token requests must share one authentication operation
`req~citedrive.refresh.single-request~1`

Requests for the same server configuration share an outstanding token request so that rotating refresh tokens are not reused concurrently.

Needs: impl, utest

## CiteDrive token requests must have finite network timeouts
`req~citedrive.token.timeout~1`

Authorization code exchange and refresh use a ten-second connection timeout and a thirty-second read timeout.
Token exchange runs outside the browser callback request thread.

Needs: impl, utest

## CiteDrive must preserve the login after retryable refresh failures
`req~citedrive.refresh.failure~1`

Network, parsing, rate limit, server, and client configuration failures retain the refresh token without starting browser authentication.
Only an `invalid_grant` response with HTTP status 400 clears the token and starts another login.

Needs: impl, utest

<!-- markdownlint-disable-file MD022 -->
4 changes: 4 additions & 0 deletions jabgui/src/main/java/module-info.java
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,10 @@

requires org.jspecify;

// region nimbusds / OAuth2
requires nimbusds.oauth2.oidc.sdk;
// endregion

// region: other libraries (alphabetically)
// requires cuid;
requires com.dlsc.pdfviewfx;
Expand Down
14 changes: 10 additions & 4 deletions jabgui/src/main/java/org/jabref/gui/JabRefGUI.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,12 @@
import org.jabref.gui.util.DirectoryMonitor;
import org.jabref.gui.util.UiTaskExecutor;
import org.jabref.gui.walkthrough.WalkthroughPane;
import org.jabref.http.manager.HttpServerManager;
import org.jabref.http.server.manager.HttpServerManager;
import org.jabref.languageserver.controller.LanguageServerController;
import org.jabref.logic.UiCommand;
import org.jabref.logic.ai.AiService;
import org.jabref.logic.citation.SearchCitationsRelationsService;
import org.jabref.logic.citedrive.OAuthSessionRegistry;
import org.jabref.logic.git.GitSsh;
import org.jabref.logic.git.util.GitHandlerRegistry;
import org.jabref.logic.journals.JournalAbbreviationLoader;
Expand Down Expand Up @@ -103,6 +104,7 @@ public class JabRefGUI extends Application {

private static RemoteListenerServerManager remoteListenerServerManager;
private static HttpServerManager httpServerManager;
private static OAuthSessionRegistry oAuthSessionRegistry;
private static LanguageServerController languageServerController;

private Stage mainStage;
Expand Down Expand Up @@ -139,7 +141,8 @@ public void start(Stage stage) {
clipBoardManager,
taskExecutor,
gitHandlerRegistry,
journalAbbreviationRepository);
journalAbbreviationRepository,
oAuthSessionRegistry);

openWindow();

Expand Down Expand Up @@ -228,6 +231,9 @@ public void initialize() {
JabRefGUI.httpServerManager = new HttpServerManager();
Injector.setModelOrService(HttpServerManager.class, JabRefGUI.httpServerManager);

JabRefGUI.oAuthSessionRegistry = new OAuthSessionRegistry();
Injector.setModelOrService(OAuthSessionRegistry.class, JabRefGUI.oAuthSessionRegistry);

JabRefGUI.languageServerController = new LanguageServerController(preferences, journalAbbreviationRepository, entryTypesManager);
Injector.setModelOrService(LanguageServerController.class, JabRefGUI.languageServerController);

Expand Down Expand Up @@ -531,7 +537,7 @@ public void startBackgroundTasks() {
}

if (remotePreferences.shouldEnableHttpServer()) {
httpServerManager.start(preferences, stateManager, mainFrame, remotePreferences.getHttpServerUri());
httpServerManager.start(preferences, stateManager, mainFrame, oAuthSessionRegistry, remotePreferences.getHttpServerUri());
}
if (remotePreferences.shouldEnableLanguageServer()) {
languageServerController.start(cliMessageHandler, remotePreferences.getLanguageServerPort());
Expand All @@ -544,7 +550,7 @@ private void setupHttpServerEnabledListener() {
// stop in all cases, because the port might have changed
httpServerManager.stop();
if (newValue) {
httpServerManager.start(preferences, stateManager, mainFrame, remotePreferences.getHttpServerUri());
httpServerManager.start(preferences, stateManager, mainFrame, oAuthSessionRegistry, remotePreferences.getHttpServerUri());
}
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,11 @@ public enum StandardActions implements Action {
GIT_PULL(Localization.lang("Pull")),
GIT_PUSH(Localization.lang("Push")),
GIT_COMMIT(Localization.lang("Commit")),
GIT_SHARE(Localization.lang("Share this library to GitHub"));
GIT_SHARE(Localization.lang("Share this library to GitHub")),

CITE_DRIVE(Localization.lang("CiteDrive")),
CITE_DRIVE_LOGIN(Localization.lang("Login...")), // "Authorize" would be the more technical term here.
CITE_DRIVE_PUSH(Localization.lang("Push to CiteDrive"));

private String text;
private final String description;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
package org.jabref.gui.citedrive;

import java.util.concurrent.CompletionException;
import java.util.concurrent.TimeoutException;

import org.jabref.gui.DialogService;
import org.jabref.gui.actions.SimpleCommand;
import org.jabref.gui.desktop.os.NativeDesktop;
import org.jabref.gui.preferences.GuiPreferences;
import org.jabref.gui.util.UiTaskExecutor;
import org.jabref.logic.citedrive.CiteDriveOAuthService;
import org.jabref.logic.citedrive.OAuthSessionRegistry;
import org.jabref.logic.l10n.Localization;
import org.jabref.logic.remote.RemotePreferences;

import org.jspecify.annotations.NullMarked;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

@NullMarked
public class CiteDriveLoginAction extends SimpleCommand {
private static final Logger LOGGER = LoggerFactory.getLogger(CiteDriveLoginAction.class);
private final DialogService dialogService;
private final CiteDriveOAuthService citeDriveOAuthService;

public CiteDriveLoginAction(DialogService dialogService, GuiPreferences preferences, OAuthSessionRegistry oAuthSessionRegistry) {
this.dialogService = dialogService;
this.citeDriveOAuthService = createOAuthService(dialogService, preferences, oAuthSessionRegistry);
}

static CiteDriveOAuthService createOAuthService(DialogService dialogService, GuiPreferences preferences, OAuthSessionRegistry oAuthSessionRegistry) {
return new CiteDriveOAuthService(
preferences.getRemotePreferences(),
preferences.getCiteDrivePreferences(),
oAuthSessionRegistry,
uri -> UiTaskExecutor.runInJavaFXThread(() -> {
dialogService.notify(Localization.lang("Opening the CiteDrive login page in the browser"));
NativeDesktop.openBrowserShowPopup(uri.toASCIIString(), dialogService, preferences.getExternalApplicationsPreferences());
}),
() -> enableHttpServer(dialogService, preferences.getRemotePreferences()));
}

/// The browser returns to JabRef's HTTP server, which is off by default, so the user is asked to switch it on.
///
/// @return whether the server is enabled now
private static boolean enableHttpServer(DialogService dialogService, RemotePreferences remotePreferences) {
boolean enable = Boolean.TRUE.equals(UiTaskExecutor.runInJavaFXThread(() -> dialogService.showConfirmationDialogAndWait(
Localization.lang("Log in to CiteDrive"),
Localization.lang("Logging in to CiteDrive needs JabRef's HTTP server, which is currently disabled."),
Localization.lang("Enable HTTP server"))));
if (enable) {
remotePreferences.setEnableHttpServer(true);
}
return enable;
}

/// User-facing reason of a failed login or push
static String describeFailure(Throwable throwable) {
Throwable cause = (throwable instanceof CompletionException && throwable.getCause() != null) ? throwable.getCause() : throwable;
if (cause instanceof TimeoutException) {
return Localization.lang("Login was not completed in time.");
}
return String.valueOf(cause.getLocalizedMessage());
}

@Override
public void execute() {
// The token itself is not needed here: the refresh token is stored in the preferences
citeDriveOAuthService
.authorizeInteractive()
.whenComplete((token, throwable) -> {
if (throwable != null) {
LOGGER.error("CiteDrive login failed", throwable);
dialogService.notify(Localization.lang("CiteDrive login failed: %0", describeFailure(throwable)));
} else if (token.isEmpty()) {
dialogService.notify(Localization.lang("CiteDrive login failed: could not obtain access token."));
}
});
}
}
Loading
Loading