Changeset 18665 in josm for trunk/src/org/openstreetmap/josm/data
- Timestamp:
- 2023-02-16T16:01:49+01:00 (23 months ago)
- Location:
- trunk/src/org/openstreetmap/josm/data/oauth
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/data/oauth/IOAuthAuthorization.java
r18650 r18665 2 2 package org.openstreetmap.josm.data.oauth; 3 3 4 import java.util.Optional; 4 5 import java.util.function.Consumer; 5 6 … … 16 17 * @param scopes The scopes to ask for 17 18 */ 18 void authorize(IOAuthParameters parameters, Consumer< IOAuthToken> consumer, Enum<?>... scopes);19 void authorize(IOAuthParameters parameters, Consumer<Optional<IOAuthToken>> consumer, Enum<?>... scopes); 19 20 } -
trunk/src/org/openstreetmap/josm/data/oauth/IOAuthParameters.java
r18650 r18665 91 91 } 92 92 93 /** 94 * Store the preferences for these parameters 95 */ 93 96 void rememberPreferences(); 94 97 } -
trunk/src/org/openstreetmap/josm/data/oauth/IOAuthToken.java
r18650 r18665 13 13 * Sign a client 14 14 * @param client The client to sign 15 * @throws OAuthException if the OAuth token type is unknown (AKA we do't know how to handle it) 15 16 */ 16 17 void sign(HttpClient client) throws OAuthException; -
trunk/src/org/openstreetmap/josm/data/oauth/OAuth20Authorization.java
r18662 r18665 13 13 import java.util.Map; 14 14 import java.util.Objects; 15 import java.util.Optional; 15 16 import java.util.UUID; 16 17 import java.util.function.Consumer; … … 45 46 46 47 @Override 47 public void authorize(IOAuthParameters parameters, Consumer< IOAuthToken> consumer, Enum<?>... scopes) {48 public void authorize(IOAuthParameters parameters, Consumer<Optional<IOAuthToken>> consumer, Enum<?>... scopes) { 48 49 final String state = UUID.randomUUID().toString(); 49 50 final String codeVerifier = UUID.randomUUID().toString(); // Cryptographically random string (ASCII) … … 62 63 private final String state; 63 64 private final IOAuthParameters parameters; 64 private final Consumer< IOAuthToken> consumer;65 private final Consumer<Optional<IOAuthToken>> consumer; 65 66 private final String codeVerifier; 66 67 67 OAuth20AuthorizationHandler(String state, String codeVerifier, IOAuthParameters parameters, Consumer< IOAuthToken> consumer) {68 OAuth20AuthorizationHandler(String state, String codeVerifier, IOAuthParameters parameters, Consumer<Optional<IOAuthToken>> consumer) { 68 69 this.state = state; 69 70 this.parameters = parameters; … … 98 99 HttpClient.Response response = tradeCodeForToken.getResponse(); 99 100 OAuth20Token oAuth20Token = new OAuth20Token(parameters, response.getContentReader()); 100 consumer.accept( oAuth20Token);101 consumer.accept(Optional.of(oAuth20Token)); 101 102 } catch (IOException | OAuth20Exception e) { 102 consumer.accept( null);103 consumer.accept(Optional.empty()); 103 104 throw new JosmRuntimeException(e); 104 105 } finally { -
trunk/src/org/openstreetmap/josm/data/oauth/OAuth20Token.java
r18650 r18665 20 20 import org.openstreetmap.josm.tools.HttpClient; 21 21 import org.openstreetmap.josm.tools.JosmRuntimeException; 22 import org.openstreetmap.josm.tools.Utils; 22 23 23 24 /** … … 81 82 @Override 82 83 public void sign(HttpClient client) throws OAuthException { 83 if (!this.oauthParameters.getApiUrl().contains(client.getURL().getHost())) { 84 if (!Utils.isBlank(this.oauthParameters.getApiUrl()) 85 && !this.oauthParameters.getApiUrl().contains(client.getURL().getHost())) { 84 86 String host = URI.create(this.oauthParameters.getAccessTokenUrl()).getHost(); 85 87 throw new IllegalArgumentException("Cannot sign URL with token for different host: Expected " + host
Note:
See TracChangeset
for help on using the changeset viewer.