-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'develop' into feature/MARP-464-Initial-sorting-of-conne…
…ctors-on-landing-page
- Loading branch information
1 parent
714047d
commit dda69b5
Showing
16 changed files
with
226 additions
and
132 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
20 changes: 20 additions & 0 deletions
20
marketplace-service/src/main/java/com/axonivy/market/constants/RequestParamConstants.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package com.axonivy.market.constants; | ||
|
||
import lombok.AccessLevel; | ||
import lombok.NoArgsConstructor; | ||
|
||
@NoArgsConstructor(access = AccessLevel.PRIVATE) | ||
public class RequestParamConstants { | ||
public static final String ID = "id"; | ||
public static final String KEY = "key"; | ||
public static final String TAG = "tag"; | ||
public static final String TYPE = "type"; | ||
public static final String KEYWORD = "keyword"; | ||
public static final String LANGUAGE = "language"; | ||
public static final String USER_ID = "userId"; | ||
public static final String AUTHORIZATION = "Authorization"; | ||
public static final String RESET_SYNC = "resetSync"; | ||
public static final String PRODUCT_ID = "productId"; | ||
public static final String SHOW_DEV_VERSION = "isShowDevVersion"; | ||
public static final String DESIGNER_VERSION = "designerVersion"; | ||
} |
12 changes: 7 additions & 5 deletions
12
marketplace-service/src/main/java/com/axonivy/market/controller/AppController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
55 changes: 30 additions & 25 deletions
55
marketplace-service/src/main/java/com/axonivy/market/controller/OAuth2Controller.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,51 +1,56 @@ | ||
package com.axonivy.market.controller; | ||
|
||
import com.axonivy.market.constants.GitHubConstants; | ||
import com.axonivy.market.entity.User; | ||
import com.axonivy.market.github.model.GitHubAccessTokenResponse; | ||
import com.axonivy.market.github.service.GitHubService; | ||
import com.axonivy.market.model.Oauth2AuthorizationCode; | ||
import com.axonivy.market.service.JwtService; | ||
import org.springframework.beans.factory.annotation.Value; | ||
import static com.axonivy.market.constants.RequestMappingConstants.AUTH; | ||
import static com.axonivy.market.constants.RequestMappingConstants.GIT_HUB_LOGIN; | ||
import static org.apache.commons.lang3.StringUtils.EMPTY; | ||
|
||
import java.util.Collections; | ||
import java.util.Map; | ||
|
||
import org.springframework.http.HttpStatus; | ||
import org.springframework.http.ResponseEntity; | ||
import org.springframework.web.bind.annotation.CrossOrigin; | ||
import org.springframework.web.bind.annotation.PostMapping; | ||
import org.springframework.web.bind.annotation.RequestBody; | ||
import org.springframework.web.bind.annotation.RequestMapping; | ||
import org.springframework.web.bind.annotation.RestController; | ||
|
||
import java.util.Collections; | ||
import com.axonivy.market.constants.GitHubConstants; | ||
import com.axonivy.market.entity.User; | ||
import com.axonivy.market.github.model.GitHubAccessTokenResponse; | ||
import com.axonivy.market.github.model.GitHubProperty; | ||
import com.axonivy.market.github.service.GitHubService; | ||
import com.axonivy.market.model.Oauth2AuthorizationCode; | ||
import com.axonivy.market.service.JwtService; | ||
|
||
@RestController | ||
@RequestMapping("/auth") | ||
@RequestMapping(AUTH) | ||
public class OAuth2Controller { | ||
|
||
@Value("${spring.security.oauth2.client.registration.github.client-id}") | ||
private String clientId; | ||
|
||
@Value("${spring.security.oauth2.client.registration.github.client-secret}") | ||
private String clientSecret; | ||
private final GitHubProperty gitHubProperty; | ||
|
||
private final GitHubService gitHubService; | ||
|
||
private final JwtService jwtService; | ||
|
||
public OAuth2Controller(GitHubService gitHubService, JwtService jwtService) { | ||
public OAuth2Controller(GitHubService gitHubService, JwtService jwtService, GitHubProperty gitHubProperty) { | ||
this.gitHubService = gitHubService; | ||
this.jwtService = jwtService; | ||
this.gitHubProperty = gitHubProperty; | ||
} | ||
|
||
@CrossOrigin("*") | ||
@PostMapping("/github/login") | ||
public ResponseEntity<Object> gitHubLogin(@RequestBody Oauth2AuthorizationCode oauth2AuthorizationCode) { | ||
GitHubAccessTokenResponse tokenResponse = gitHubService.getAccessToken(oauth2AuthorizationCode.getCode(), clientId, | ||
clientSecret); | ||
String accessToken = tokenResponse.getAccessToken(); | ||
@PostMapping(GIT_HUB_LOGIN) | ||
public ResponseEntity<Map<String, String>> gitHubLogin(@RequestBody Oauth2AuthorizationCode oauth2AuthorizationCode) { | ||
String accessToken = EMPTY; | ||
try { | ||
GitHubAccessTokenResponse tokenResponse = gitHubService.getAccessToken(oauth2AuthorizationCode.getCode(), | ||
gitHubProperty); | ||
accessToken = tokenResponse.getAccessToken(); | ||
} catch (Exception e) { | ||
return new ResponseEntity<>(Map.of(e.getClass().getName(), e.getMessage()), HttpStatus.BAD_REQUEST); | ||
} | ||
|
||
User user = gitHubService.getAndUpdateUser(accessToken); | ||
|
||
String jwtToken = jwtService.generateToken(user); | ||
|
||
return ResponseEntity.ok().body(Collections.singletonMap(GitHubConstants.Json.TOKEN, jwtToken)); | ||
return new ResponseEntity<>(Collections.singletonMap(GitHubConstants.Json.TOKEN, jwtToken), HttpStatus.OK); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.