package com.perforce.workspace.tjuricek.p4oauth.config; import java.io.UnsupportedEncodingException; import java.net.URLEncoder; import static com.perforce.workspace.tjuricek.p4oauth.controllers.LoginGet.LOGIN_PATH; /** */ public class UrlFactory { private P4OAuthConfig config; public UrlFactory(P4OAuthConfig config) { this.config = config; } public P4OAuthConfig getConfig() { return config; } public void setConfig(P4OAuthConfig config) { this.config = config; } public String getLoginUrl(String login, String redirectUri, String state) { try { return getP4OAuthUrl() + LOGIN_PATH + "?" + "client_id=" + login + "&" + "redirect_uri=" + URLEncoder.encode(redirectUri, "utf8") + (state != null ? "&state=" + URLEncoder.encode(state, "utf8") : ""); } catch (UnsupportedEncodingException e) { throw new IllegalStateException(e); } } public String getP4OAuthUrl() { StringBuilder url = new StringBuilder(); url.append("https://"); url.append(config.getHostname()); if (config.getHttpsPort() != 443) { url.append(":").append(config.getHttpsPort()); } if (config.getContextRoot() != null) { url.append(config.getContextRoot()); } return url.toString(); } public String createAuthRedirect(String redirectUri, String code, String state) { try { return redirectUri + "?" + "code=" + URLEncoder.encode(code, "utf8") + (state != null ? "&state=" + URLEncoder.encode(state, "utf8") : ""); } catch (UnsupportedEncodingException e) { throw new IllegalStateException(e); } } }
# | Change | User | Description | Committed | |
---|---|---|---|---|---|
#2 | 9095 | tjuricek | Added some basic test data and renamed "workspace" to "workshop" in package name | ||
#1 | 9089 | tjuricek |
Moving some code that worked via some manual validation to the workshop. This just implements a basic code authorization grant scheme. Automated tests are forthcoming, awating some gradle plugin work that should sit outside of this project. |