Skip to content

Commit 13e81c2

Browse files
committed
Merged Feature/generic oauth #875
1 parent 47351bf commit 13e81c2

File tree

5 files changed

+23
-8
lines changed

5 files changed

+23
-8
lines changed

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

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@
44
import lombok.experimental.SuperBuilder;
55
import lombok.extern.jackson.Jacksonized;
66

7+
import static org.lowcoder.sdk.auth.constants.Oauth2Constants.BASE_URL_PLACEHOLDER;
8+
import static org.lowcoder.sdk.auth.constants.Oauth2Constants.SCOPE_PLACEHOLDER;
9+
710
/**
811
* This class is for Generic Auth Provider
912
*/
@@ -20,4 +23,14 @@ public class Oauth2GenericAuthConfig extends Oauth2SimpleAuthConfig {
2023
private String userInfoEndpoint;
2124
private String scope;
2225
private Boolean userInfoIntrospection;
26+
27+
@Override
28+
public String replaceAuthUrlClientIdPlaceholder(String url)
29+
{
30+
return super.replaceAuthUrlClientIdPlaceholder(url)
31+
.replace(BASE_URL_PLACEHOLDER, authorizationEndpoint)
32+
.replace(SCOPE_PLACEHOLDER, scope);
33+
}
34+
35+
2336
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ public String getAuthorizeUrl() {
3838
case AuthTypeConstants.GITHUB -> replaceAuthUrlClientIdPlaceholder(Oauth2Constants.GITHUB_AUTHORIZE_URL);
3939
case AuthTypeConstants.ORY -> replaceAuthUrlClientIdPlaceholder(Oauth2Constants.ORY_AUTHORIZE_URL);
4040
case AuthTypeConstants.KEYCLOAK -> replaceAuthUrlClientIdPlaceholder(Oauth2Constants.KEYCLOAK_AUTHORIZE_URL);
41-
case AuthTypeConstants.GENERIC -> ((Oauth2GenericAuthConfig)this).getAuthorizationEndpoint();
41+
case AuthTypeConstants.GENERIC -> replaceAuthUrlClientIdPlaceholder(Oauth2Constants.GENERIC_AUTHORIZE_URL);
4242
default -> null;
4343
};
4444
}

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

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,4 +41,13 @@ public class Oauth2Constants {
4141
+ "&redirect_uri=" + REDIRECT_URL_PLACEHOLDER
4242
+ "&state=" + STATE_PLACEHOLDER
4343
+ "&scope=" + SCOPE_PLACEHOLDER;
44+
45+
public static final String GENERIC_AUTHORIZE_URL = BASE_URL_PLACEHOLDER
46+
+ "?response_type=code"
47+
+ "&client_id=" + CLIENT_ID_PLACEHOLDER
48+
+ "&redirect_uri=" + REDIRECT_URL_PLACEHOLDER
49+
+ "&state=" + STATE_PLACEHOLDER
50+
+ "&scope=" + SCOPE_PLACEHOLDER
51+
+ "&access_type=offline"
52+
+ "&prompt=select_account";
4453
}

server/api-service/lowcoder-server/src/main/java/org/lowcoder/api/authentication/service/AuthenticationApiServiceImpl.java

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -418,12 +418,6 @@ private boolean addOrUpdateNewAuthConfig(Organization organization, AbstractAuth
418418
.stream()
419419
.collect(Collectors.toMap(AbstractAuthConfig::getId, Function.identity()));
420420

421-
boolean authTypeAlreadyExists = authConfigMap.values().stream()
422-
.anyMatch(config -> !config.getId().equals(newAuthConfig.getId()) && config.getAuthType().equals(newAuthConfig.getAuthType()));
423-
if(authTypeAlreadyExists) {
424-
return false;
425-
}
426-
427421
// Under the organization, the source can uniquely identify the whole auth config.
428422
AbstractAuthConfig old = authConfigMap.get(newAuthConfig.getId());
429423
if (old != null) {

server/api-service/lowcoder-server/src/main/java/org/lowcoder/api/authentication/service/factory/AuthConfigFactoryImpl.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ public class AuthConfigFactoryImpl implements AuthConfigFactory {
1919

2020
@Override
2121
public AbstractAuthConfig build(AuthConfigRequest authConfigRequest, boolean enable) {
22-
buildOauth2GenericAuthConfig(authConfigRequest, enable);
2322
return switch (authConfigRequest.getAuthType()) {
2423
case AuthTypeConstants.FORM -> buildEmailAuthConfig(authConfigRequest, enable);
2524
case AuthTypeConstants.GITHUB -> buildOauth2SimpleAuthConfig(GITHUB, GITHUB_NAME, authConfigRequest, enable);

0 commit comments

Comments
 (0)