Class OAuthParameters
java.lang.Object
org.openstreetmap.josm.data.oauth.OAuthParameters
This class manages an immutable set of OAuth parameters.
- Since:
- 2747 (static factory class since 18991)
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic IOAuthParametersReplies a set of default parameters for a consumer accessing the standard OSM server atIUrls.getDefaultOsmApiUrl().static IOAuthParameterscreateDefault(String apiUrl, OAuthVersion oAuthVersion) Replies a set of default parameters for a consumer accessing an OSM server at the given API url.static IOAuthParameterscreateFromApiUrl(String apiUrl, OAuthVersion oAuthVersion) Replies a set of parameters as defined in the preferences: the parameters of the access token of the server, otherwise the parameters the user entered, unless the server is set touse the default parameters, otherwise thedefault parameters.private static IOAuthParameterscreateFromPreferences(String... keys) Get the OAuth 2.0 parameters the user entered in the advanced OAuth settings and saved withIOAuthParameters.rememberPreferences(), or the parameters of the access token of the server.private static OAuth20ParametersgetDefaultOAuth20Parameters(String apiUrl) Get the default OAuth 2.0 parametersstatic StringGet the host of an API, which is what the OAuth settings and the access token of a server are stored under.(package private) static StringgetPreferenceKey(String apiUrl) Get the preference key under which the OAuth 2.0 parameters for the server of an API are stored.private static jakarta.json.JsonObjectgetRFC8414Parameters(String apiUrl) private static StringgetWebsite(String apiUrl) Get the website of an OSM API server, where openstreetmap-website has its OAuth 2.0 endpoints: the API URL without its/api, except for the default OSM API, which is served from a host of its own.static booleanisUseDefault(String apiUrl) Determines whether the default OAuth 2.0 parameters are used for the server of an API, that is the ones built into JOSM or published by the server, rather than the ones the user entered in the advanced OAuth settings.private static OAuth20ParametersparseAuthorizationServerMetadataResponse(String clientId, String clientSecret, String apiUrl, String redirectUri, jakarta.json.JsonObject serverMetadata) Parse the response from RFC 8414 (OAuth 2.0 Authorization Server Metadata)static voidsetUseDefault(String apiUrl, boolean useDefault) Sets whether the default OAuth 2.0 parameters are used for the server of an API.
-
Field Details
-
RFC8414_RESPONSES
-
OSM_API_DEFAULT
- See Also:
-
OSM_API_DEV
- See Also:
-
OSM_API_MASTER
- See Also:
-
USE_DEFAULT
Whether the default parameters are used; one setting for each host, with the setting for all hosts as fallback- See Also:
-
-
Constructor Details
-
OAuthParameters
private OAuthParameters()
-
-
Method Details
-
createDefault
Replies a set of default parameters for a consumer accessing the standard OSM server atIUrls.getDefaultOsmApiUrl().Note that this may make network requests for RFC 8414 compliant endpoints.
- Returns:
- a set of default parameters
-
createDefault
Replies a set of default parameters for a consumer accessing an OSM server at the given API url. URL parameters are only set if the URL equalsIUrls.getDefaultOsmApiUrl()or references the domain "dev.openstreetmap.org", otherwise they may benull.Note that this may make network requests for RFC 8414 compliant endpoints.
- Parameters:
apiUrl- The API URL for which the OAuth default parameters are created. If null or empty, the default OSM API url is used.oAuthVersion- The OAuth version to create default parameters for- Returns:
- a set of default parameters for the given
apiUrl - Since:
- 18650
-
createFromPreferences
Get the OAuth 2.0 parameters the user entered in the advanced OAuth settings and saved withIOAuthParameters.rememberPreferences(), or the parameters of the access token of the server. Until a token exists, this is the only place a client id for a server not increateDefault(String, OAuthVersion)can come from.OAuth20Parameters.rememberPreferences()keys by the host of the API, as the access token is; earlier versions of JOSM keyed them by the API URL, so callers pass that too.- Parameters:
keys- The preference key suffixes to try, in order- Returns:
- The remembered parameters, or
nullif none are saved or they cannot be parsed - Since:
- 19627
-
getPreferenceKey
Get the preference key under which the OAuth 2.0 parameters for the server of an API are stored. This is the key of the access token of that server too, seeCredentialsAgent.- Parameters:
apiUrl- The API URL, or the host of the API- Returns:
- The preference key
- Since:
- 19707
-
getHost
Get the host of an API, which is what the OAuth settings and the access token of a server are stored under.- Parameters:
apiUrl- The API URL, or the host of the API- Returns:
- The host, or
apiUrlitself if it is not a URL (includingnull) - Since:
- 19707
-
isUseDefault
Determines whether the default OAuth 2.0 parameters are used for the server of an API, that is the ones built into JOSM or published by the server, rather than the ones the user entered in the advanced OAuth settings.This is a setting of each server. Until it is set for a server, the setting earlier versions of JOSM had for all servers is used.
- Parameters:
apiUrl- The API URL, or the host of the API- Returns:
trueif the default parameters are used- Since:
- 19707
-
setUseDefault
Sets whether the default OAuth 2.0 parameters are used for the server of an API.- Parameters:
apiUrl- The API URL, or the host of the APIuseDefault-trueto use the default parameters,falseto use the ones the user entered- Since:
- 19707
- See Also:
-
getRFC8414Parameters
-
getDefaultOAuth20Parameters
Get the default OAuth 2.0 parameters- Parameters:
apiUrl- The API url- Returns:
- The default parameters
-
getWebsite
Get the website of an OSM API server, where openstreetmap-website has its OAuth 2.0 endpoints: the API URL without its/api, except for the default OSM API, which is served from a host of its own.- Parameters:
apiUrl- The normalized API URL- Returns:
- The website URL
-
parseAuthorizationServerMetadataResponse
private static OAuth20Parameters parseAuthorizationServerMetadataResponse(String clientId, String clientSecret, String apiUrl, String redirectUri, jakarta.json.JsonObject serverMetadata) throws OAuthException Parse the response from RFC 8414 (OAuth 2.0 Authorization Server Metadata)- Returns:
- The parameters for the server metadata
- Throws:
OAuthException
-
createFromApiUrl
Replies a set of parameters as defined in the preferences: the parameters of the access token of the server, otherwise the parameters the user entered, unless the server is set touse the default parameters, otherwise thedefault parameters.- Parameters:
oAuthVersion- The OAuth version to use.apiUrl- the API URL. Must not benull.- Returns:
- the parameters
- Since:
- 18650
-