Skip to content

Commit

Permalink
Add external OAuth URL option so we can use docker network URLs for d…
Browse files Browse the repository at this point in the history
…irect access within the stack
  • Loading branch information
ryanrdoherty committed Jul 2, 2024
1 parent c9631b6 commit 41555ba
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 2 deletions.
3 changes: 3 additions & 0 deletions Model/lib/rng/wdkModel-config.rng
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,9 @@
<optional>
<attribute name="oauthUrl"/>
</optional>
<optional>
<attribute name="externalOauthUrl"/>
</optional>
<optional>
<attribute name="oauthClientId"/>
</optional>
Expand Down
12 changes: 11 additions & 1 deletion Model/src/main/java/org/gusdb/wdk/model/config/ModelConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@ public String getName() {
*/
private final AuthenticationMethod _authenticationMethod;
private final String _oauthUrl; // needed if method is OAUTH2
private final String _externalOauthUrl; // may be needed if method is OAUTH2 and internal URL is not available externally
private final String _oauthClientId; // needed if method is OAUTH2
private final String _oauthClientSecret; // needed if method is OAUTH2
private final String _changePasswordUrl; // probably needed if method is OAUTH2
Expand All @@ -150,7 +151,7 @@ public ModelConfig(String modelName, String projectId, Path gusHome, boolean cac
String emailContent, ModelConfigUserDB userDB, ModelConfigAppDB appDB,
ModelConfigUserDatasetStore userDatasetStoreConfig, QueryMonitor queryMonitor,
boolean monitorBlockedThreads, int blockedThreshold, AuthenticationMethod authenticationMethod,
String oauthUrl, String oauthClientId, String oauthClientSecret, String changePasswordUrl,
String oauthUrl, String externalOauthUrl, String oauthClientId, String oauthClientSecret, String changePasswordUrl,
String keyStoreFile, String keyStorePassPhrase) {

// basic model information
Expand Down Expand Up @@ -195,6 +196,7 @@ public ModelConfig(String modelName, String projectId, Path gusHome, boolean cac
// user authentication setup
_authenticationMethod = authenticationMethod;
_oauthUrl = oauthUrl;
_externalOauthUrl = externalOauthUrl;
_oauthClientId = oauthClientId;
_oauthClientSecret = oauthClientSecret;
_changePasswordUrl = changePasswordUrl;
Expand Down Expand Up @@ -338,6 +340,14 @@ public String getOauthUrl() {
return _oauthUrl;
}

/**
* @return base URL of OAuth2 server to use for authentication
* (called only if authentication method is OAUTH2)
*/
public String getExternalOauthUrl() {
return _externalOauthUrl == null || _externalOauthUrl.isBlank() ? _externalOauthUrl : _oauthUrl;
}

/**
* @return OAuth2 client ID to use for authentication
* (called only if authentication method is OAUTH2)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ public class ModelConfigBuilder {
// user authentication setup
private AuthenticationMethod _authenticationMethod = AuthenticationMethod.USER_DB;
private String _oauthUrl = ""; // needed if method is OAUTH2
private String _externalOauthUrl = ""; // may be needed if method is OAUTH2 and internal URL is not available externally
private String _oauthClientId = ""; // needed if method is OAUTH2
private String _oauthClientSecret = ""; // needed if method is OAUTH2
private String _changePasswordUrl = ""; // probably needed if method is OAUTH2
Expand Down Expand Up @@ -137,6 +138,7 @@ public ModelConfig build() throws WdkModelException {
// user authentication setup
_authenticationMethod,
_oauthUrl,
_externalOauthUrl,
_oauthClientId,
_oauthClientSecret,
_changePasswordUrl,
Expand Down Expand Up @@ -269,6 +271,17 @@ public void setOauthUrl(String oauthUrl) {
_oauthUrl = oauthUrl;
}

/**
* @param externalOauthUrl base URL of OAuth2 server to use for authentication
* (used only if authentication method is OAUTH2). This may differ from the
* (internal) oauthUrl for some deployments. The external value is returned to
* external clients, telling them how to connect to OAuth. The internal value
* is what WDK actually uses to connect directly to OAuth.
*/
public void setExternalOauthUrl(String externalOauthUrl) {
_externalOauthUrl = externalOauthUrl;
}

/**
* @param oauthClientId OAuth2 client ID to use for authentication
* (used only if authentication method is OAUTH2)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,8 @@ public static JSONObject getWdkProjectInfo(WdkModel wdkModel, String serviceEndp
// create authentication config sub-object
JSONObject authConfig = new JSONObject()
.put(JsonKeys.AUTHENTICATION_METHOD, config.getAuthenticationMethodEnum().name())
.put(JsonKeys.OAUTH_URL, config.getOauthUrl())
// Tell client to use external URL
.put(JsonKeys.OAUTH_URL, config.getExternalOauthUrl())
// Always use HTTPS
.put(JsonKeys.OAUTH_CLIENT_URL, serviceEndpoint.replace("http","https"))
.put(JsonKeys.OAUTH_CLIENT_ID, config.getOauthClientId());
Expand Down

0 comments on commit 41555ba

Please sign in to comment.