Skip to content

Commit 2d8c7df

Browse files
authored
Merge pull request #54 from common-workflow-language/oauth
Add oauth support
2 parents 5e8ca27 + a758fe4 commit 2d8c7df

File tree

2 files changed

+16
-3
lines changed

2 files changed

+16
-3
lines changed

src/main/java/org/commonwl/viewer/services/GitHubService.java

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,9 @@
2222
import org.apache.commons.io.IOUtils;
2323
import org.commonwl.viewer.domain.GithubDetails;
2424
import org.eclipse.egit.github.core.*;
25+
import org.eclipse.egit.github.core.RepositoryContents;
26+
import org.eclipse.egit.github.core.RepositoryId;
27+
import org.eclipse.egit.github.core.User;
2528
import org.eclipse.egit.github.core.client.GitHubClient;
2629
import org.eclipse.egit.github.core.service.CommitService;
2730
import org.eclipse.egit.github.core.service.ContentsService;
@@ -53,12 +56,15 @@ public class GitHubService {
5356
private final Pattern githubDirPattern = Pattern.compile(GITHUB_DIR_REGEX);
5457

5558
@Autowired
56-
public GitHubService(@Value("${githubAPI.authentication}") boolean authEnabled,
59+
public GitHubService(@Value("${githubAPI.authentication}") String authSetting,
60+
@Value("${githubAPI.oauthToken}") String token,
5761
@Value("${githubAPI.username}") String username,
5862
@Value("${githubAPI.password}") String password) {
5963
GitHubClient client = new GitHubClient();
60-
if (authEnabled) {
64+
if (authSetting.equals("basic")) {
6165
client.setCredentials(username, password);
66+
} else if (authSetting.equals("oauth")) {
67+
client.setOAuth2Token(token);
6268
}
6369
this.contentsService = new ContentsService(client);
6470
this.userService = new UserService(client);

src/main/resources/application.properties

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,17 @@ totalFileSizeLimit = 10000000
2626
#=======================
2727

2828
# Authentication increases rate limit from 50 requests/hr to 5000 requests/hr
29-
githubAPI.authentication = false
29+
30+
# Should be none/basic/oauth
31+
githubAPI.authentication = none
32+
33+
# Basic authentication details used if githubAPI.authentication = false
3034
githubAPI.username = username
3135
githubAPI.password = password
3236

37+
# Oauth token used if githubAPI.authentication = oauth
38+
githubAPI.oauthToken = token
39+
3340
#=======================
3441
# MongoDB settings
3542
#=======================

0 commit comments

Comments
 (0)