Skip to content

Commit de62a2f

Browse files
committed
new: use scope provided from frontend
1 parent 7105b92 commit de62a2f

File tree

3 files changed

+16
-4
lines changed

3 files changed

+16
-4
lines changed

server/api-service/lowcoder-sdk/src/main/java/org/lowcoder/sdk/auth/Oauth2KeycloakAuthConfig.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import static org.lowcoder.sdk.auth.constants.Oauth2Constants.BASE_URL_PLACEHOLDER;
44
import static org.lowcoder.sdk.auth.constants.Oauth2Constants.REALM_PLACEHOLDER;
5+
import static org.lowcoder.sdk.auth.constants.Oauth2Constants.SCOPE_PLACEHOLDER;
56

67
import com.fasterxml.jackson.annotation.JsonCreator;
78
import com.fasterxml.jackson.annotation.JsonProperty;
@@ -17,6 +18,7 @@ public class Oauth2KeycloakAuthConfig extends Oauth2SimpleAuthConfig
1718
{
1819
protected String baseUrl;
1920
protected String realm;
21+
protected String scope;
2022

2123
@JsonCreator
2224
public Oauth2KeycloakAuthConfig(
@@ -29,11 +31,13 @@ public Oauth2KeycloakAuthConfig(
2931
@JsonProperty("clientSecret") String clientSecret,
3032
@JsonProperty("baseUrl") String baseUrl,
3133
@JsonProperty("realm") String realm,
34+
@JsonProperty("scope") String scope,
3235
@JsonProperty("authType") String authType)
3336
{
3437
super(id, enable, enableRegister, source, sourceName, clientId, clientSecret, authType);
3538
this.baseUrl = baseUrl;
3639
this.realm = realm;
40+
this.scope = scope;
3741
}
3842

3943

@@ -43,7 +47,8 @@ public String replaceAuthUrlClientIdPlaceholder(String url)
4347
{
4448
return super.replaceAuthUrlClientIdPlaceholder(url)
4549
.replace(BASE_URL_PLACEHOLDER, baseUrl)
46-
.replace(REALM_PLACEHOLDER, realm);
50+
.replace(REALM_PLACEHOLDER, realm)
51+
.replace(SCOPE_PLACEHOLDER, scope);
4752
}
4853

4954

server/api-service/lowcoder-sdk/src/main/java/org/lowcoder/sdk/auth/Oauth2OryAuthConfig.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package org.lowcoder.sdk.auth;
22

33
import static org.lowcoder.sdk.auth.constants.Oauth2Constants.BASE_URL_PLACEHOLDER;
4+
import static org.lowcoder.sdk.auth.constants.Oauth2Constants.SCOPE_PLACEHOLDER;
45

56
import javax.annotation.Nullable;
67

@@ -15,6 +16,7 @@
1516
public class Oauth2OryAuthConfig extends Oauth2SimpleAuthConfig {
1617

1718
protected String baseUrl;
19+
protected String scope;
1820

1921
@JsonCreator
2022
public Oauth2OryAuthConfig(
@@ -26,13 +28,17 @@ public Oauth2OryAuthConfig(
2628
String clientId,
2729
String clientSecret,
2830
String baseUrl,
31+
String scope,
2932
String authType) {
3033
super(id, enable, enableRegister, source, sourceName, clientId, clientSecret, authType);
3134
this.baseUrl = baseUrl;
35+
this.scope = scope;
3236
}
3337

3438
@Override
3539
public String replaceAuthUrlClientIdPlaceholder(String url) {
36-
return super.replaceAuthUrlClientIdPlaceholder(url).replace(BASE_URL_PLACEHOLDER, baseUrl);
40+
return super.replaceAuthUrlClientIdPlaceholder(url)
41+
.replace(BASE_URL_PLACEHOLDER, baseUrl)
42+
.replace(SCOPE_PLACEHOLDER, scope);
3743
}
3844
}

server/api-service/lowcoder-sdk/src/main/java/org/lowcoder/sdk/auth/constants/Oauth2Constants.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ public class Oauth2Constants {
99
public static final String REALM_PLACEHOLDER = "$REALM";
1010

1111
public static final String BASE_URL_PLACEHOLDER = "$BASE_URL";
12+
public static final String SCOPE_PLACEHOLDER = "$SCOPE";
1213

1314
// authorize url
1415
public static final String GITHUB_AUTHORIZE_URL = "https://github.com/login/oauth/authorize"
@@ -32,12 +33,12 @@ public class Oauth2Constants {
3233
+ "&client_id=" + CLIENT_ID_PLACEHOLDER
3334
+ "&redirect_uri=" + REDIRECT_URL_PLACEHOLDER
3435
+ "&state=" + STATE_PLACEHOLDER
35-
+ "&scope=openid email profile offline_access";
36+
+ "&scope=" + SCOPE_PLACEHOLDER;
3637

3738
public static final String KEYCLOAK_AUTHORIZE_URL = BASE_URL_PLACEHOLDER + "/realms/" + REALM_PLACEHOLDER + "/protocol/openid-connect/auth"
3839
+ "?response_type=code"
3940
+ "&client_id=" + CLIENT_ID_PLACEHOLDER
4041
+ "&redirect_uri=" + REDIRECT_URL_PLACEHOLDER
4142
+ "&state=" + STATE_PLACEHOLDER
42-
+ "&scope=openid email profile";
43+
+ "&scope=" + SCOPE_PLACEHOLDER;
4344
}

0 commit comments

Comments
 (0)