Ignore:
Timestamp:
2024-03-06T15:07:01+01:00 (3 months ago)
Author:
taylor.smock
Message:

Fix an issue with custom OAuth2 parameters where the custom parameters would be replaced by default parameters

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/gui/oauth/OAuthAuthorizationWizard.java

    r18991 r19008  
    8484        if ((this.oAuthVersion == OAuthVersion.OAuth20 || this.oAuthVersion == OAuthVersion.OAuth21)
    8585        && this.procedure == AuthorizationProcedure.FULLY_AUTOMATIC) {
    86             authorize(true, callback, this.apiUrl, this.oAuthVersion);
     86            authorize(true, callback, this.apiUrl, this.oAuthVersion, getOAuthParameters());
    8787        } else {
    8888            setVisible(true);
     
    9090                throw new UserCancelException();
    9191            }
    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        }
    9696    }
    9797
    9898    /**
    9999     * Perform the oauth dance
     100     *
    100101     * @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) {
    106109        final boolean remoteControlIsRunning = Boolean.TRUE.equals(RemoteControl.PROP_REMOTECONTROL_ENABLED.get());
    107110        // TODO: Ask user if they want to start remote control?
     
    109112            RemoteControl.start();
    110113        }
    111         new OAuth20Authorization().authorize(OAuthParameters.createDefault(apiUrl, oAuthVersion), token -> {
     114        new OAuth20Authorization().authorize(
     115                Optional.ofNullable(oAuthParameters).orElseGet(() -> OAuthParameters.createDefault(apiUrl, oAuthVersion)),
     116                token -> {
    112117                    if (!remoteControlIsRunning) {
    113118                        RemoteControl.stop();
     
    253258     * Creates the wizard.
    254259     *
    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
    260266     * @throws IllegalArgumentException if apiUrl is null
    261267     */
    262268    public OAuthAuthorizationWizard(Component parent, AuthorizationProcedure procedure, String apiUrl,
    263                                     Executor executor, OAuthVersion oAuthVersion) {
     269                                    Executor executor, OAuthVersion oAuthVersion, IOAuthParameters advancedParameters) {
    264270        super(GuiHelper.getFrameForComponent(parent), ModalityType.DOCUMENT_MODAL);
    265271        this.procedure = Objects.requireNonNull(procedure, "procedure");
     
    268274        this.oAuthVersion = oAuthVersion;
    269275        build();
     276        if (advancedParameters != null) {
     277            pnlFullyAutomaticAuthorisationUI.getAdvancedPropertiesPanel().setAdvancedParameters(advancedParameters);
     278            pnlManualAuthorisationUI.getAdvancedPropertiesPanel().setAdvancedParameters(advancedParameters);
     279        }
    270280    }
    271281
     
    362372                    AuthorizationProcedure.FULLY_AUTOMATIC,
    363373                    serverUrl.toString(), Utils.newDirectExecutor(),
    364                     OAuthVersion.OAuth20);
     374                    OAuthVersion.OAuth20, null);
    365375            wizard.showDialog(null);
    366376            return wizard;
Note: See TracChangeset for help on using the changeset viewer.