Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitb106575

Browse files
authored
Merge pull request#572 from lowcoder-org/link-oauth-providers-for-existing-users
Link Oauth Providers Feature For Existing Users
2 parents2b20d3f +0a96750 commitb106575

File tree

8 files changed

+57
-10
lines changed

8 files changed

+57
-10
lines changed

‎server/api-service/lowcoder-sdk/src/main/java/org/lowcoder/sdk/config/AuthProperties.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ public class AuthProperties {
2828
privateOauth2Simplegoogle =newOauth2Simple();
2929
privateOauth2Simplegithub =newOauth2Simple();
3030
privateApiKeyapiKey =newApiKey();
31+
privateBooleanworkspaceCreation;
3132

3233
@Getter
3334
@Setter

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

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ public Mono<ResponseView<Boolean>> formLogin(@RequestBody FormLoginRequest formL
4646
ServerWebExchangeexchange) {
4747
returnauthenticationApiService.authenticateByForm(formLoginRequest.loginId(),formLoginRequest.password(),
4848
formLoginRequest.source(),formLoginRequest.register(),formLoginRequest.authId(),orgId)
49-
.flatMap(user ->authenticationApiService.loginOrRegister(user,exchange,invitationId))
49+
.flatMap(user ->authenticationApiService.loginOrRegister(user,exchange,invitationId,Boolean.FALSE))
5050
.thenReturn(ResponseView.success(true));
5151
}
5252

@@ -63,7 +63,20 @@ public Mono<ResponseView<Boolean>> loginWithThirdParty(
6363
@RequestParamStringorgId,
6464
ServerWebExchangeexchange) {
6565
returnauthenticationApiService.authenticateByOauth2(authId,source,code,redirectUrl,orgId)
66-
.flatMap(authUser ->authenticationApiService.loginOrRegister(authUser,exchange,invitationId))
66+
.flatMap(authUser ->authenticationApiService.loginOrRegister(authUser,exchange,invitationId,Boolean.FALSE))
67+
.thenReturn(ResponseView.success(true));
68+
}
69+
70+
@Override
71+
publicMono<ResponseView<Boolean>>linkAccountWithThirdParty(
72+
@RequestParam(required =false)StringauthId,
73+
@RequestParam(required =false)Stringsource,
74+
@RequestParamStringcode,
75+
@RequestParamStringredirectUrl,
76+
@RequestParamStringorgId,
77+
ServerWebExchangeexchange) {
78+
returnauthenticationApiService.authenticateByOauth2(authId,source,code,redirectUrl,orgId)
79+
.flatMap(authUser ->authenticationApiService.loginOrRegister(authUser,exchange,null,Boolean.TRUE))
6780
.thenReturn(ResponseView.success(true));
6881
}
6982

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

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,24 @@ public Mono<ResponseView<Boolean>> loginWithThirdParty(
6969
@RequestParamStringorgId,
7070
ServerWebExchangeexchange);
7171

72+
/**
73+
* Link current account with third party auth provider
74+
*/
75+
@Operation(
76+
tags =TAG_AUTHENTICATION,
77+
operationId ="linkAccountWithTP",
78+
summary ="Link current account with third party auth provider",
79+
description ="Authenticate a Lowcoder User using third-party login credentials and link to the existing session/account"
80+
)
81+
@PostMapping("/tp/link")
82+
publicMono<ResponseView<Boolean>>linkAccountWithThirdParty(
83+
@RequestParam(required =false)StringauthId,
84+
@RequestParam(required =false)Stringsource,
85+
@RequestParamStringcode,
86+
@RequestParamStringredirectUrl,
87+
@RequestParamStringorgId,
88+
ServerWebExchangeexchange);
89+
7290
@Operation(
7391
tags =TAG_AUTHENTICATION,
7492
operationId ="logout",

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ public interface AuthenticationApiService {
1616

1717
Mono<AuthUser>authenticateByOauth2(StringauthId,Stringsource,Stringcode,StringredirectUrl,StringorgId);
1818

19-
Mono<Void>loginOrRegister(AuthUserauthUser,ServerWebExchangeexchange,StringinvitationId);
19+
Mono<Void>loginOrRegister(AuthUserauthUser,ServerWebExchangeexchange,StringinvitationId,booleanlinKExistingUser);
2020

2121
Mono<Boolean>enableAuthConfig(AuthConfigRequestauthConfigRequest);
2222

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

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
importorg.lowcoder.domain.user.model.*;
3030
importorg.lowcoder.domain.user.service.UserService;
3131
importorg.lowcoder.sdk.auth.AbstractAuthConfig;
32+
importorg.lowcoder.sdk.config.AuthProperties;
3233
importorg.lowcoder.sdk.exception.BizError;
3334
importorg.lowcoder.sdk.exception.BizException;
3435
importorg.lowcoder.sdk.util.CookieHelper;
@@ -85,6 +86,9 @@ public class AuthenticationApiServiceImpl implements AuthenticationApiService {
8586
@Autowired
8687
privateJWTUtilsjwtUtils;
8788

89+
@Autowired
90+
privateAuthPropertiesauthProperties;
91+
8892
@Override
8993
publicMono<AuthUser>authenticateByForm(StringloginId,Stringpassword,Stringsource,booleanregister,StringauthId,StringorgId) {
9094
returnauthenticate(authId,source,newFormAuthRequestContext(loginId,password,register,orgId));
@@ -130,8 +134,8 @@ protected Mono<AuthUser> authenticate(String authId, @Deprecated String source,
130134

131135
@Override
132136
publicMono<Void>loginOrRegister(AuthUserauthUser,ServerWebExchangeexchange,
133-
StringinvitationId) {
134-
returnupdateOrCreateUser(authUser)
137+
StringinvitationId,booleanlinKExistingUser) {
138+
returnupdateOrCreateUser(authUser,linKExistingUser)
135139
.delayUntil(user ->ReactiveSecurityContextHolder.getContext()
136140
.doOnNext(securityContext ->securityContext.setAuthentication(AuthenticationUtils.toAuthentication(user))))
137141
// save token and set cookie
@@ -142,7 +146,9 @@ public Mono<Void> loginOrRegister(AuthUser authUser, ServerWebExchange exchange,
142146
})
143147
// after register
144148
.delayUntil(user -> {
145-
if (user.getIsNewUser()) {
149+
booleancreateWorkspace =
150+
authUser.getOrgId() ==null &&StringUtils.isBlank(invitationId) &&authProperties.getWorkspaceCreation();
151+
if (user.getIsNewUser() &&createWorkspace) {
146152
returnonUserRegister(user);
147153
}
148154
returnMono.empty();
@@ -160,7 +166,13 @@ public Mono<Void> loginOrRegister(AuthUser authUser, ServerWebExchange exchange,
160166
.then(businessEventPublisher.publishUserLoginEvent(authUser.getSource()));
161167
}
162168

163-
privateMono<User>updateOrCreateUser(AuthUserauthUser) {
169+
privateMono<User>updateOrCreateUser(AuthUserauthUser,booleanlinkExistingUser) {
170+
171+
if(linkExistingUser) {
172+
returnsessionUserService.getVisitor()
173+
.flatMap(user ->userService.addNewConnectionAndReturnUser(user.getId(),authUser.toAuthConnection()));
174+
}
175+
164176
returnfindByAuthUserSourceAndRawId(authUser).zipWith(findByAuthUserRawId(authUser))
165177
.flatMap(tuple -> {
166178

‎server/api-service/lowcoder-server/src/main/resources/application-lowcoder.yml

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@ spring:
33
mongodb:
44
authentication-database:admin
55
auto-index-creation:false
6-
uri:mongodb://lowcoder:secret123@localhost:27017/lowcoder?authSource=admin
6+
uri:mongodb://192.168.8.103:27017/lowcoder?authSource=admin
77
redis:
8-
url:redis://localhost:6379
8+
url:redis://192.168.8.103:6379
99
main:
1010
allow-bean-definition-overriding:true
1111
allow-circular-references:true
@@ -61,4 +61,5 @@ auth:
6161
secret:5a41b090758b39b226603177ef48d73ae9839dd458ccb7e66f7e7cc028d5a50b
6262
email:
6363
enable:true
64-
enable-register:true
64+
enable-register:true
65+
workspace-creation:false

‎server/api-service/lowcoder-server/src/main/resources/selfhost/ce/application-selfhost.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ auth:
1313
email:
1414
enable:${LOGIN_CHANNEL_EMAIL:true}
1515
enable-register:${ENABLE_USER_SIGN_UP:true}
16+
workspace-creation:${LOWCODER_CREATE_SIGNUP_WORKSPACE:true}
1617

1718
spring:
1819
data:

‎server/api-service/lowcoder-server/src/main/resources/selfhost/ce/application.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ auth:
44
email:
55
enable:true
66
enable-register:${ENABLE_USER_SIGN_UP:true}
7+
workspace-creation:${LOWCODER_CREATE_SIGNUP_WORKSPACE:true}
78

89
spring:
910
data:

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp