Skip to content

Commit

Permalink
Added proof key and rename port parameter name
Browse files Browse the repository at this point in the history
  • Loading branch information
sfc-gh-igarish committed Oct 21, 2023
1 parent f848717 commit f40706e
Showing 1 changed file with 12 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@
import org.apache.http.client.utils.URLEncodedUtils;
import org.apache.http.entity.StringEntity;

import java.security.SecureRandom;

/**
* SAML 2.0 Compliant service/application federated authentication 1. Query GS to obtain IDP SSO url
* 2. Listen a localhost port to accept Saml response 3. Open a browser in the backend so that the
Expand Down Expand Up @@ -217,12 +219,14 @@ private String getSSOUrl(int port) throws SFException, SnowflakeSQLException {

private String getConsoleLoginUrl(int port) throws SFException {
try {
String proofKey = generateProofKey();
String serverUrl = loginInput.getServerUrl();

URIBuilder consoleLoginUriBuilder = new URIBuilder(serverUrl);
consoleLoginUriBuilder.setPath(SessionUtil.SF_PATH_CONSOLE_LOGIN_REQUEST);
consoleLoginUriBuilder.addParameter("login_name", loginInput.getUserName());
consoleLoginUriBuilder.addParameter("client_port", Integer.toString(port));
consoleLoginUriBuilder.addParameter("browser_mode_redirect_port", Integer.toString(port));
consoleLoginUriBuilder.addParameter("proof_key", proofKey);

String consoleLoginUrl = consoleLoginUriBuilder.build().toURL().toString();

Expand All @@ -234,6 +238,13 @@ private String getConsoleLoginUrl(int port) throws SFException {
}
}

private String generateProofKey() {
SecureRandom secureRandom = new SecureRandom();
byte[] randomness = new byte[32];
secureRandom.nextBytes(randomness);
return Base64.getEncoder().encodeToString(randomness);
}

/**
* Authenticate
*
Expand Down

0 comments on commit f40706e

Please sign in to comment.