Skip to content

Commit

Permalink
Add repo scope for github oAuth authorization.
Browse files Browse the repository at this point in the history
  • Loading branch information
Dmytro Rezchykov committed Nov 18, 2021
1 parent b76d155 commit cf161db
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,13 @@ public class GithubOAuthFlow extends BaseOAuth2Flow {

private static final String AUTHORIZE_URL = "https://github.com/login/oauth/authorize";
private static final String ACCESS_TOKEN_URL = "https://github.com/login/oauth/access_token";
// Setting "repo" scope would allow grant not only read but also write
// access to our application. Unfortunatelly we cannot follow least
// privelege principle here cause github has no option of granular access
// tune up.
// This is necessary to pull data from private repositories.
// https://docs.github.com/en/developers/apps/building-oauth-apps/scopes-for-oauth-apps#available-scopes
private static final String SCOPES = "repo";

public GithubOAuthFlow(final ConfigRepository configRepository, final HttpClient httpClient) {
super(configRepository, httpClient);
Expand All @@ -41,11 +48,10 @@ protected String formatConsentUrl(final UUID definitionId,
final JsonNode inputOAuthConfiguration)
throws IOException {
try {
// No scope means read-only access to public information
// https://docs.github.com/en/developers/apps/building-oauth-apps/scopes-for-oauth-apps#available-scopes
return new URIBuilder(AUTHORIZE_URL)
.addParameter("client_id", clientId)
.addParameter("redirect_uri", redirectUrl)
.addParameter("scope", SCOPES)
.addParameter("state", getState())
.build().toString();
} catch (final URISyntaxException e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ protected BaseOAuthFlow getOAuthFlow() {

@Override
protected String getExpectedConsentUrl() {
return "https://github.com/login/oauth/authorize?client_id=test_client_id&redirect_uri=https%3A%2F%2Fairbyte.io&state=state";
return "https://github.com/login/oauth/authorize?client_id=test_client_id&redirect_uri=https%3A%2F%2Fairbyte.io&scope=repo&state=state";
}

@Override
Expand Down

0 comments on commit cf161db

Please sign in to comment.