Class OAuthParameters

java.lang.Object
org.openstreetmap.josm.data.oauth.OAuthParameters

public final class OAuthParameters extends Object
This class manages an immutable set of OAuth parameters.
Since:
2747 (static factory class since 18991)
  • Field Details

  • Constructor Details

  • Method Details

    • createDefault

      Replies a set of default parameters for a consumer accessing the standard OSM server at IUrls.getDefaultOsmApiUrl().

      Note that this may make network requests for RFC 8414 compliant endpoints.

      Returns:
      a set of default parameters
    • createDefault

      public static IOAuthParameters createDefault(String apiUrl, OAuthVersion oAuthVersion)
      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 equals IUrls.getDefaultOsmApiUrl() or references the domain "dev.openstreetmap.org", otherwise they may be null.

      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

      private static IOAuthParameters createFromPreferences(String... keys)
      Get the OAuth 2.0 parameters the user entered in the advanced OAuth settings and saved with IOAuthParameters.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 in createDefault(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 null if none are saved or they cannot be parsed
      Since:
      19627
    • getPreferenceKey

      static String getPreferenceKey(String apiUrl)
      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, see CredentialsAgent.
      Parameters:
      apiUrl - The API URL, or the host of the API
      Returns:
      The preference key
      Since:
      19707
    • getHost

      public static String getHost(String apiUrl)
      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 apiUrl itself if it is not a URL (including null)
      Since:
      19707
    • isUseDefault

      public static boolean isUseDefault(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.

      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:
      true if the default parameters are used
      Since:
      19707
    • setUseDefault

      public static void setUseDefault(String apiUrl, boolean useDefault)
      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 API
      useDefault - true to use the default parameters, false to use the ones the user entered
      Since:
      19707
      See Also:
    • getRFC8414Parameters

      private static jakarta.json.JsonObject getRFC8414Parameters(String apiUrl)
    • getDefaultOAuth20Parameters

      Get the default OAuth 2.0 parameters
      Parameters:
      apiUrl - The API url
      Returns:
      The default parameters
    • getWebsite

      private static String getWebsite(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.
      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

      public static IOAuthParameters createFromApiUrl(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 to use the default parameters, otherwise the default parameters.
      Parameters:
      oAuthVersion - The OAuth version to use.
      apiUrl - the API URL. Must not be null.
      Returns:
      the parameters
      Since:
      18650