Ignore:
Timestamp:
2023-06-20T19:40:11+02:00 (3 years ago)
Author:
taylor.smock
Message:

Fix #22952, #23013: Improve methods for seeing who is logged in to OSM

This adds a Test Authentication button to the OAuth 2 panel and updates the
current UserIdentityManager to have the appropriate details. In addition, this
fixes a problem whereby a user logged in via OAuth 2 would not be able to log in
via OAuth 1.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/gui/preferences/server/OAuthAuthenticationPreferencesPanel.java

    r18667 r18764  
    283283                // these want the OAuth 1.0 token information
    284284                btns.add(new JButton(new RenewAuthorisationAction(AuthorizationProcedure.FULLY_AUTOMATIC)));
    285                 btns.add(new JButton(new TestAuthorisationAction()));
    286             }
     285            }
     286            btns.add(new JButton(new TestAuthorisationAction(oAuthVersion)));
    287287            btns.add(new JButton(new RemoveAuthorisationAction()));
    288288            gc.gridy = 4;
     
    423423     */
    424424    private class TestAuthorisationAction extends AbstractAction {
     425        private final OAuthVersion oAuthVersion;
     426
    425427        /**
    426428         * Constructs a new {@code TestAuthorisationAction}.
    427429         */
    428         TestAuthorisationAction() {
     430        TestAuthorisationAction(OAuthVersion oAuthVersion) {
     431            this.oAuthVersion = oAuthVersion;
    429432            putValue(NAME, tr("Test Access Token"));
    430433            putValue(SHORT_DESCRIPTION, tr("Click test access to the OSM server with the current access token"));
     
    434437        @Override
    435438        public void actionPerformed(ActionEvent evt) {
    436             OAuthToken token = OAuthAccessTokenHolder.getInstance().getAccessToken();
    437             OAuthParameters parameters = OAuthParameters.createFromApiUrl(OsmApi.getOsmApi().getServerUrl());
    438             TestAccessTokenTask task = new TestAccessTokenTask(
    439                     OAuthAuthenticationPreferencesPanel.this,
    440                     apiUrl,
    441                     parameters,
    442                     token
    443             );
    444             MainApplication.worker.submit(task);
     439            if (this.oAuthVersion == OAuthVersion.OAuth10a) {
     440                OAuthToken token = OAuthAccessTokenHolder.getInstance().getAccessToken();
     441                OAuthParameters parameters = OAuthParameters.createFromApiUrl(OsmApi.getOsmApi().getServerUrl());
     442                TestAccessTokenTask task = new TestAccessTokenTask(
     443                        OAuthAuthenticationPreferencesPanel.this,
     444                        apiUrl,
     445                        parameters,
     446                        token
     447                );
     448                MainApplication.worker.submit(task);
     449            } else {
     450                IOAuthToken token = OAuthAccessTokenHolder.getInstance().getAccessToken(OsmApi.getOsmApi().getBaseUrl(), OAuthVersion.OAuth20);
     451                TestAccessTokenTask task = new TestAccessTokenTask(
     452                        OAuthAuthenticationPreferencesPanel.this,
     453                        apiUrl,
     454                        token.getParameters(),
     455                        token
     456                );
     457                MainApplication.worker.submit(task);
     458            }
    445459        }
    446460    }
Note: See TracChangeset for help on using the changeset viewer.