Skip to content

Commit 815098b

Browse files
committed
added option to send host_url as an index appended to appid in the state parameter of an auth request
1 parent 25377ce commit 815098b

File tree

1 file changed

+26
-28
lines changed

1 file changed

+26
-28
lines changed

src/main/java/com/erudika/scoold/utils/ScooldUtils.java

Lines changed: 26 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -2248,73 +2248,70 @@ public String getCSPNonce() {
22482248

22492249
public String getFacebookLoginURL() {
22502250
return "https://www.facebook.com/dialog/oauth?client_id=" + CONF.facebookAppId() +
2251-
"&response_type=code&scope=email&state=" + getParaAppId() +
2252-
"&redirect_uri=" + getParaEndpoint() + "/facebook_auth" + getHostUrlParam();
2251+
"&response_type=code&scope=email&state=" + getStateParam() +
2252+
"&redirect_uri=" + getParaEndpoint() + "/facebook_auth";
22532253
}
22542254

22552255
public String getGoogleLoginURL() {
22562256
return "https://accounts.google.com/o/oauth2/v2/auth?client_id=" + CONF.googleAppId() +
2257-
"&response_type=code&scope=openid%20profile%20email&state=" + getParaAppId() +
2258-
"&redirect_uri=" + getParaEndpoint() + "/google_auth" + getHostUrlParam();
2257+
"&response_type=code&scope=openid%20profile%20email&state=" + getStateParam() +
2258+
"&redirect_uri=" + getParaEndpoint() + "/google_auth";
22592259
}
22602260

22612261
public String getGitHubLoginURL() {
22622262
return "https://github.com/login/oauth/authorize?response_type=code&client_id=" + CONF.githubAppId() +
2263-
"&scope=user%3Aemail&state=" + getParaAppId() +
2264-
"&redirect_uri=" + getParaEndpoint() + "/github_auth" + getHostUrlParam();
2263+
"&scope=user%3Aemail&state=" + getStateParam() +
2264+
"&redirect_uri=" + getParaEndpoint() + "/github_auth";
22652265
}
22662266

22672267
public String getLinkedInLoginURL() {
22682268
return "https://www.linkedin.com/oauth/v2/authorization?response_type=code&client_id=" + CONF.linkedinAppId() +
2269-
"&scope=r_liteprofile%20r_emailaddress&state=" + getParaAppId() +
2270-
"&redirect_uri=" + getParaEndpoint() + "/linkedin_auth" + getHostUrlParam();
2269+
"&scope=r_liteprofile%20r_emailaddress&state=" + getStateParam() +
2270+
"&redirect_uri=" + getParaEndpoint() + "/linkedin_auth";
22712271
}
22722272

22732273
public String getTwitterLoginURL() {
2274-
return getParaEndpoint() + "/twitter_auth?state=" + getParaAppId();
2274+
return getParaEndpoint() + "/twitter_auth?state=" + getStateParam();
22752275
}
22762276

22772277
public String getMicrosoftLoginURL() {
22782278
return "https://login.microsoftonline.com/" + CONF.microsoftTenantId() +
22792279
"/oauth2/v2.0/authorize?response_type=code&client_id=" + CONF.microsoftAppId() +
2280-
"&scope=https%3A%2F%2Fgraph.microsoft.com%2Fuser.read&state=" + getParaAppId() +
2281-
"&redirect_uri=" + getParaEndpoint() + "/microsoft_auth" + getHostUrlParam();
2280+
"&scope=https%3A%2F%2Fgraph.microsoft.com%2Fuser.read&state=" + getStateParam() +
2281+
"&redirect_uri=" + getParaEndpoint() + "/microsoft_auth";
22822282
}
22832283

22842284
public String getSlackLoginURL() {
22852285
return "https://slack.com/oauth/v2/authorize?response_type=code&client_id=" + CONF.slackAppId() +
2286-
"&user_scope=identity.basic%20identity.email%20identity.team%20identity.avatar&state=" + getParaAppId() +
2287-
"&redirect_uri=" + getParaEndpoint() + "/slack_auth" + getHostUrlParam();
2286+
"&user_scope=identity.basic%20identity.email%20identity.team%20identity.avatar&state=" + getStateParam() +
2287+
"&redirect_uri=" + getParaEndpoint() + "/slack_auth";
22882288
}
22892289

22902290
public String getAmazonLoginURL() {
22912291
return "https://www.amazon.com/ap/oa?response_type=code&client_id=" + CONF.amazonAppId() +
2292-
"&scope=profile&state=" + getParaAppId() +
2293-
"&redirect_uri=" + getParaEndpoint() + "/amazon_auth" + getHostUrlParam();
2292+
"&scope=profile&state=" + getStateParam() +
2293+
"&redirect_uri=" + getParaEndpoint() + "/amazon_auth";
22942294
}
22952295

22962296
public String getOAuth2LoginURL() {
22972297
return CONF.oauthAuthorizationUrl("") + "?" +
22982298
"response_type=code&client_id=" + CONF.oauthAppId("") +
22992299
"&scope=" + CONF.oauthScope("") + getOauth2StateParam("") +
2300-
"&redirect_uri=" + getParaEndpoint() + "/oauth2_auth" + getOauth2AppidParam("") +
2301-
getHostUrlParam(CONF.oauthAppidInStateParamEnabled(""));
2300+
"&redirect_uri=" + getParaEndpoint() + "/oauth2_auth" + getOauth2AppidParam("");
23022301
}
23032302

23042303
public String getOAuth2SecondLoginURL() {
23052304
return CONF.oauthAuthorizationUrl("second") + "?" +
23062305
"response_type=code&client_id=" + CONF.oauthAppId("second") +
23072306
"&scope=" + CONF.oauthScope("second") + getOauth2StateParam("second") +
2308-
"&redirect_uri=" + getParaEndpoint() + "/oauth2_auth" + getOauth2AppidParam("second") +
2309-
getHostUrlParam(CONF.oauthAppidInStateParamEnabled("second"));
2307+
"&redirect_uri=" + getParaEndpoint() + "/oauth2_auth" + getOauth2AppidParam("second");
23102308
}
23112309

23122310
public String getOAuth2ThirdLoginURL() {
23132311
return CONF.oauthAuthorizationUrl("third") + "?" +
23142312
"response_type=code&client_id=" + CONF.oauthAppId("third") +
23152313
"&scope=" + CONF.oauthScope("third") + getOauth2StateParam("third") +
2316-
"&redirect_uri=" + getParaEndpoint() + "/oauth2_auth" + getOauth2AppidParam("third") +
2317-
getHostUrlParam(CONF.oauthAppidInStateParamEnabled("third"));
2314+
"&redirect_uri=" + getParaEndpoint() + "/oauth2_auth" + getOauth2AppidParam("third");
23182315
}
23192316

23202317
public String getParaEndpoint() {
@@ -2326,19 +2323,20 @@ public String getParaAppId() {
23262323
}
23272324

23282325
private String getOauth2StateParam(String a) {
2329-
return "&state=" + (CONF.oauthAppidInStateParamEnabled(a) ? getParaAppId() : UUID.randomUUID().toString());
2326+
return "&state=" + (CONF.oauthAppidInStateParamEnabled(a) ? getStateParam() : UUID.randomUUID().toString());
23302327
}
23312328

23322329
private String getOauth2AppidParam(String a) {
23332330
return CONF.oauthAppidInStateParamEnabled(a) ? "" : "?appid=" + getParaAppId();
23342331
}
23352332

2336-
private String getHostUrlParam() {
2337-
return getHostUrlParam(true);
2338-
}
2339-
2340-
private String getHostUrlParam(boolean isSingleParam) {
2341-
return StringUtils.isBlank(CONF.hostUrlAliases()) ? "" : ((isSingleParam ? "?" : "&") + "host_url=" + CONF.serverUrl());
2333+
private String getStateParam() {
2334+
if (StringUtils.isBlank(CONF.hostUrlAliases())) {
2335+
return getParaAppId();
2336+
} else {
2337+
int index = Arrays.asList(CONF.hostUrlAliases().split("\\s*,\\s*")).indexOf(CONF.serverUrl());
2338+
return getParaAppId() + (index >= 0 ? "|" + index : "");
2339+
}
23422340
}
23432341

23442342
public String getFirstConfiguredLoginURL() {

0 commit comments

Comments
 (0)