Changeset 19008 in josm for trunk/src/org/openstreetmap
- Timestamp:
- 2024-03-06T15:07:01+01:00 (8 months ago)
- Location:
- trunk/src/org/openstreetmap/josm
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/data/oauth/OAuthParameters.java
r18991 r19008 197 197 */ 198 198 public static IOAuthParameters createFromApiUrl(String apiUrl, OAuthVersion oAuthVersion) { 199 IOAuthParameters parameters = createDefault(apiUrl, oAuthVersion); 199 // We actually need the host 200 if (apiUrl.startsWith("https://") || apiUrl.startsWith("http://")) { 201 try { 202 apiUrl = new URI(apiUrl).getHost(); 203 } catch (URISyntaxException syntaxException) { 204 Logging.trace(apiUrl); 205 } 206 } 200 207 switch (oAuthVersion) { 201 208 case OAuth20: 202 209 case OAuth21: // Right now, OAuth 2.1 will work with our OAuth 2.0 implementation 203 OAuth20Parameters oAuth20Parameters = (OAuth20Parameters) parameters;204 210 try { 205 211 IOAuthToken storedToken = CredentialsManager.getInstance().lookupOAuthAccessToken(apiUrl); 206 return storedToken != null ? storedToken.getParameters() : oAuth20Parameters; 212 if (storedToken != null) { 213 return storedToken.getParameters(); 214 } 207 215 } catch (CredentialsAgentException e) { 208 216 Logging.trace(e); 209 217 } 210 return oAuth20Parameters;218 return createDefault(apiUrl, oAuthVersion); 211 219 default: 212 220 throw new IllegalArgumentException("Unknown OAuth version: " + oAuthVersion); -
trunk/src/org/openstreetmap/josm/gui/oauth/AdvancedOAuthPropertiesPanel.java
r18991 r19008 215 215 tfConsumerKey.getText(), 216 216 tfConsumerSecret.getText(), 217 tfAccessTokenURL.getText(), 217 218 tfAuthoriseURL.getText(), 218 tfAccessTokenURL.getText(),219 apiUrl, 219 220 tfRequestTokenURL.getText() 220 221 ); … … 261 262 this.resetToDefaultSettings(); 262 263 } else { 263 setAdvancedParameters(OAuthParameters.createFromApiUrl(paramApiUrl, OAuthVersion.OAuth20)); 264 // createFromApiUrl may make a network request 265 final IOAuthParameters parameters = OAuthParameters.createFromApiUrl(paramApiUrl, OAuthVersion.OAuth20); 266 GuiHelper.runInEDT(() -> setAdvancedParameters(parameters)); 264 267 } 265 268 GuiHelper.runInEDT(() -> ilUseDefault.setEnabled(true)); -
trunk/src/org/openstreetmap/josm/gui/oauth/FullyAutomaticAuthorizationUI.java
r18991 r19008 381 381 }); 382 382 } 383 }, getApiUrl(), getOAuthVersion() );383 }, getApiUrl(), getOAuthVersion(), getOAuthParameters()); 384 384 getProgressMonitor().worked(1); 385 385 } -
trunk/src/org/openstreetmap/josm/gui/oauth/OAuthAuthorizationWizard.java
r18991 r19008 84 84 if ((this.oAuthVersion == OAuthVersion.OAuth20 || this.oAuthVersion == OAuthVersion.OAuth21) 85 85 && this.procedure == AuthorizationProcedure.FULLY_AUTOMATIC) { 86 authorize(true, callback, this.apiUrl, this.oAuthVersion );86 authorize(true, callback, this.apiUrl, this.oAuthVersion, getOAuthParameters()); 87 87 } else { 88 88 setVisible(true); … … 90 90 throw new UserCancelException(); 91 91 } 92 }93 OAuthAccessTokenHolder holder = OAuthAccessTokenHolder.getInstance();94 holder.setAccessToken(apiUrl, getAccessToken());95 holder.setSaveToPreferences(isSaveAccessTokenToPreferences());92 OAuthAccessTokenHolder holder = OAuthAccessTokenHolder.getInstance(); 93 holder.setAccessToken(apiUrl, getAccessToken()); 94 holder.setSaveToPreferences(isSaveAccessTokenToPreferences()); 95 } 96 96 } 97 97 98 98 /** 99 99 * Perform the oauth dance 100 * 100 101 * @param startRemoteControl {@code true} to start remote control if it is not already running 101 * @param callback The callback to use to notify that the OAuth dance succeeded 102 * @param apiUrl The API URL to get the token for 103 * @param oAuthVersion The OAuth version that the authorization dance is force 104 */ 105 static void authorize(boolean startRemoteControl, Consumer<Optional<IOAuthToken>> callback, String apiUrl, OAuthVersion oAuthVersion) { 102 * @param callback The callback to use to notify that the OAuth dance succeeded 103 * @param apiUrl The API URL to get the token for 104 * @param oAuthVersion The OAuth version that the authorization dance is force 105 * @param oAuthParameters The OAuth parameters to use 106 */ 107 static void authorize(boolean startRemoteControl, Consumer<Optional<IOAuthToken>> callback, String apiUrl, 108 OAuthVersion oAuthVersion, IOAuthParameters oAuthParameters) { 106 109 final boolean remoteControlIsRunning = Boolean.TRUE.equals(RemoteControl.PROP_REMOTECONTROL_ENABLED.get()); 107 110 // TODO: Ask user if they want to start remote control? … … 109 112 RemoteControl.start(); 110 113 } 111 new OAuth20Authorization().authorize(OAuthParameters.createDefault(apiUrl, oAuthVersion), token -> { 114 new OAuth20Authorization().authorize( 115 Optional.ofNullable(oAuthParameters).orElseGet(() -> OAuthParameters.createDefault(apiUrl, oAuthVersion)), 116 token -> { 112 117 if (!remoteControlIsRunning) { 113 118 RemoteControl.stop(); … … 253 258 * Creates the wizard. 254 259 * 255 * @param parent the component relative to which the dialog is displayed 256 * @param procedure the authorization procedure to use 257 * @param apiUrl the API URL. Must not be null. 258 * @param executor the executor used for running the HTTP requests for the authorization 259 * @param oAuthVersion The OAuth version this wizard is for 260 * @param parent the component relative to which the dialog is displayed 261 * @param procedure the authorization procedure to use 262 * @param apiUrl the API URL. Must not be null. 263 * @param executor the executor used for running the HTTP requests for the authorization 264 * @param oAuthVersion The OAuth version this wizard is for 265 * @param advancedParameters The OAuth parameters to initialize the wizard with 260 266 * @throws IllegalArgumentException if apiUrl is null 261 267 */ 262 268 public OAuthAuthorizationWizard(Component parent, AuthorizationProcedure procedure, String apiUrl, 263 Executor executor, OAuthVersion oAuthVersion ) {269 Executor executor, OAuthVersion oAuthVersion, IOAuthParameters advancedParameters) { 264 270 super(GuiHelper.getFrameForComponent(parent), ModalityType.DOCUMENT_MODAL); 265 271 this.procedure = Objects.requireNonNull(procedure, "procedure"); … … 268 274 this.oAuthVersion = oAuthVersion; 269 275 build(); 276 if (advancedParameters != null) { 277 pnlFullyAutomaticAuthorisationUI.getAdvancedPropertiesPanel().setAdvancedParameters(advancedParameters); 278 pnlManualAuthorisationUI.getAdvancedPropertiesPanel().setAdvancedParameters(advancedParameters); 279 } 270 280 } 271 281 … … 362 372 AuthorizationProcedure.FULLY_AUTOMATIC, 363 373 serverUrl.toString(), Utils.newDirectExecutor(), 364 OAuthVersion.OAuth20 );374 OAuthVersion.OAuth20, null); 365 375 wizard.showDialog(null); 366 376 return wizard; -
trunk/src/org/openstreetmap/josm/gui/preferences/server/OAuthAuthenticationPreferencesPanel.java
r19007 r19008 331 331 final String currentApiUrl = apiUrl; 332 332 MainApplication.worker.execute(() -> { 333 final String clientId = OAuthParameters.create Default(apiUrl, oAuthVersion).getClientId();333 final String clientId = OAuthParameters.createFromApiUrl(apiUrl, oAuthVersion).getClientId(); 334 334 if (Objects.equals(apiUrl, currentApiUrl)) { 335 335 GuiHelper.runInEDT(() -> this.setEnabled(!Utils.isEmpty(clientId))); … … 347 347 apiUrl, 348 348 MainApplication.worker, 349 oAuthVersion); 349 oAuthVersion, 350 pnlAdvancedProperties.getAdvancedParameters() 351 ); 350 352 try { 351 353 wizard.showDialog(token -> GuiHelper.runInEDT(OAuthAuthenticationPreferencesPanel.this::refreshView)); … … 407 409 @Override 408 410 public void actionPerformed(ActionEvent evt) { 409 IOAuthToken token = OAuthAccessTokenHolder.getInstance().getAccessToken( OsmApi.getOsmApi().getBaseUrl(), OAuthVersion.OAuth20);411 IOAuthToken token = OAuthAccessTokenHolder.getInstance().getAccessToken(apiUrl, OAuthVersion.OAuth20); 410 412 TestAccessTokenTask task = new TestAccessTokenTask( 411 413 OAuthAuthenticationPreferencesPanel.this,
Note:
See TracChangeset
for help on using the changeset viewer.