Changes between Initial Version and Version 1 of Ticket #22596, comment 29


Ignore:
Timestamp:
2023-12-19T22:10:10+01:00 (2 years ago)
Author:
hhtznr

Legend:

Unmodified
Added
Removed
Modified
  • Ticket #22596, comment 29

    initial v1  
    1313{{{#!java
    1414private static OAuth20Token createEarthdataOAuthToken(String bearerToken) {
    15         // Either client ID or bearer token must be non-null/non-blank
    16         if (bearerToken == null || Utils.isBlank(bearerToken))
    17             return null;
    18         JsonObjectBuilder jsonObjectBuilder = Json.createObjectBuilder();
    19         jsonObjectBuilder.add("token_type", "bearer");
    20         jsonObjectBuilder.add("access_token", bearerToken);
    21         String json = jsonObjectBuilder.build().toString();
     15    // Either client ID or bearer token must be non-null/non-blank
     16    if (bearerToken == null || Utils.isBlank(bearerToken))
     17        return null;
     18    JsonObjectBuilder jsonObjectBuilder = Json.createObjectBuilder();
     19    jsonObjectBuilder.add("token_type", "bearer");
     20    jsonObjectBuilder.add("access_token", bearerToken);
     21    String json = jsonObjectBuilder.build().toString();
    2222
    23         String earthDataURS = "https://" + EARTHDATA_SSO_HOST + "/";
    24         String earthDataDL = "https://" + EARTHDATA_DOWNLOAD_HOST + "/";
    25         // Earthdata neither provides us a client ID nor a client secret
    26         String clientId = "";
    27         String clientSecret = null;
    28         // Following two URLs are set because the parameters may not be null, but are
    29         // never used
    30         String authorizeUrl = earthDataURS;
    31         String redirectUri = earthDataURS;
    32         // These two parameters need to be set to the URL of the SRTM download server
    33         // Otherwise, OAuth20Parameters will refuse to be initialized and
    34         // OAuthToken.sign(HttpClient) will refuse to do its job
    35         String tokenUrl = earthDataDL;
    36         String apiUrl = earthDataDL;
     23    String earthDataURS = "https://" + EARTHDATA_SSO_HOST + "/";
     24    String earthDataDL = "https://" + EARTHDATA_DOWNLOAD_HOST + "/";
     25    // Earthdata neither provides us a client ID nor a client secret
     26    String clientId = "";
     27    String clientSecret = null;
     28    // Following two URLs are set because the parameters may not be null, but are
     29    // never used
     30    String authorizeUrl = earthDataURS;
     31    String redirectUri = earthDataURS;
     32    // These two parameters need to be set to the URL of the SRTM download server
     33    // Otherwise, OAuth20Parameters will refuse to be initialized and
     34    // OAuthToken.sign(HttpClient) will refuse to do its job
     35    String tokenUrl = earthDataDL;
     36    String apiUrl = earthDataDL;
    3737
    38         OAuth20Parameters parameters = new OAuth20Parameters(clientId, clientSecret, tokenUrl, authorizeUrl, apiUrl,
    39                 redirectUri);
    40         try {
    41             return new OAuth20Token(parameters, json);
    42         } catch (OAuth20Exception e) {
    43             Logging.error("Elevation: " + e);
    44             return null;
    45         }
     38    OAuth20Parameters parameters = new OAuth20Parameters(clientId, clientSecret, tokenUrl, authorizeUrl, apiUrl,
     39            redirectUri);
     40    try {
     41        return new OAuth20Token(parameters, json);
     42    } catch (OAuth20Exception e) {
     43        Logging.error("Elevation: " + e);
     44        return null;
    4645    }
     46}
    4747}}}
    4848- It is to note that we do not know a client ID in this specific case. As it may not be `null`, I set it to a blank string in order to pass the null check in the `OAuth20Parameters` constructor.