-
Notifications
You must be signed in to change notification settings - Fork 4.6k
🎉 Source Gitlab: add OAuth2.0
authentication support
#7506
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 41 commits
Commits
Show all changes
45 commits
Select commit
Hold shift + click to select a range
e1cea7e
added support of oauth2.0
6934a2d
added OAuthFlow.java part
ac6dd9e
bumped version of the Dockerfile
37af9c0
corrected SAT
5ecff85
added unit_test for Oauth java part, added integration-test for java …
26612c4
added changelog
98e03ec
fix java part test
af49c77
updated after review
bd67cec
Merge remote-tracking branch 'origin/master' into bazarnov/7480-gitla…
ec26576
updated spec.json
ee22f2b
Merge remote-tracking branch 'origin/master' into bazarnov/7480-gitla…
ac15b82
updated after review
8ede858
Merge branch 'master' into bazarnov/7480-gitlab-oauth
davydov-d 3ab2f00
Merge branch 'master' into bazarnov/7480-gitlab-oauth
davydov-d a06e575
#7480 source gitlab: rm empty files
davydov-d 2f31254
#7480 source gitlab: add single use refresh token authenticator
davydov-d 6840a23
#7480 source gitlab: upd oauth implementation
davydov-d b119ccb
Merge branch 'master' into bazarnov/7480-gitlab-oauth
davydov-d fc458a2
#7480 source gitlab: refactor auth
davydov-d 5551985
Merge branch 'master' into bazarnov/7480-gitlab-oauth
alafanechere 853c2b7
Merge branch 'master' into bazarnov/7480-gitlab-oauth
davydov-d fad195e
Merge branch 'master' into bazarnov/7480-gitlab-oauth
davydov-d 8f17e3e
#7480 fix oauth: java
davydov-d da55d45
Merge branch 'bazarnov/7480-gitlab-oauth' of github.com:airbytehq/air…
davydov-d 39bf3d3
Merge branch 'master' into bazarnov/7480-gitlab-oauth
davydov-d c2cb032
Merge branch 'master' into bazarnov/7480-gitlab-oauth
davydov-d 229e3c0
#7480 source gitlab: review fixes
davydov-d 52439df
Merge branch 'master' into bazarnov/7480-gitlab-oauth
davydov-d 266eb98
Merge branch 'master' into bazarnov/7480-gitlab-oauth
davydov-d ae5b0bc
Merge branch 'master' into bazarnov/7480-gitlab-oauth
davydov-d 4be38bc
#7480 source gitlab: upd release stage
davydov-d 880cbfa
#7480 source gitlab: fix unit tests
davydov-d 4d1a6d1
#7480 source gitlab: update expected records
davydov-d 1515ab2
Merge branch 'master' into bazarnov/7480-gitlab-oauth
davydov-d 0b494f1
#7480 source gitlab: upd sats
davydov-d 5000dfb
#7480 source gitlab: upd expected records
davydov-d 67209d4
Merge branch 'master' into bazarnov/7480-gitlab-oauth
davydov-d 41f06cb
Merge branch 'master' into bazarnov/7480-gitlab-oauth
davydov-d c3dfe00
#7480 source Gitlab: use SingleUseRefreshTokenOauth as is
davydov-d 59b3637
Merge branch 'master' into bazarnov/7480-gitlab-oauth
davydov-d d13c5d1
Merge branch 'master' into bazarnov/7480-gitlab-oauth
davydov-d 0da8ab6
#7480 sourcte gitlab: upd expected records
davydov-d 7052aed
Merge branch 'bazarnov/7480-gitlab-oauth' of github.com:airbytehq/air…
davydov-d 550f5ad
auto-bump connector version
octavia-squidington-iii 9df8fa1
Merge branch 'master' into bazarnov/7480-gitlab-oauth
davydov-d File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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
18 changes: 9 additions & 9 deletions
18
airbyte-integrations/connectors/source-gitlab/integration_tests/expected_records.jsonl
Large diffs are not rendered by default.
Oops, something went wrong.
12 changes: 8 additions & 4 deletions
12
airbyte-integrations/connectors/source-gitlab/integration_tests/invalid_config.json
This file contains hidden or 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,7 +1,11 @@ | ||
{ | ||
"api_url": "gitlab.com", | ||
"private_token": "private_token-fake", | ||
"groups": "new-group", | ||
"projects": "new-ci-test", | ||
"start_date": "2021-01-01T00:00:00Z" | ||
} | ||
"start_date": "2021-01-01T00:00:00Z", | ||
"groups": "new-group-airbute", | ||
"projects": "new-group-airbute/new-ci-test-project", | ||
"credentials": { | ||
"auth_type": "access_token", | ||
"access_token": "migrated_from_old_config" | ||
} | ||
} |
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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
125 changes: 125 additions & 0 deletions
125
airbyte-oauth/src/main/java/io/airbyte/oauth/flows/GitlabOAuthFlow.java
This file contains hidden or 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,125 @@ | ||
/* | ||
* Copyright (c) 2022 Airbyte, Inc., all rights reserved. | ||
*/ | ||
|
||
package io.airbyte.oauth.flows; | ||
|
||
import com.fasterxml.jackson.databind.JsonNode; | ||
import com.google.common.collect.ImmutableMap; | ||
import io.airbyte.config.persistence.ConfigNotFoundException; | ||
import io.airbyte.config.persistence.ConfigRepository; | ||
import io.airbyte.oauth.BaseOAuth2Flow; | ||
import java.io.IOException; | ||
import java.net.URISyntaxException; | ||
import java.net.http.HttpClient; | ||
import java.time.Clock; | ||
import java.time.Instant; | ||
import java.util.HashMap; | ||
import java.util.Map; | ||
import java.util.UUID; | ||
import java.util.function.Supplier; | ||
import org.apache.http.client.utils.URIBuilder; | ||
|
||
/** | ||
* Following docs from https://docs.gitlab.com/ee/api/oauth2.html#authorization-code-flow | ||
*/ | ||
public class GitlabOAuthFlow extends BaseOAuth2Flow { | ||
|
||
private static final String ACCESS_TOKEN_URL = "https://%s/oauth/token"; | ||
private final Clock clock; | ||
|
||
public GitlabOAuthFlow(final ConfigRepository configRepository, final HttpClient httpClient) { | ||
super(configRepository, httpClient); | ||
this.clock = Clock.systemUTC(); | ||
} | ||
|
||
public GitlabOAuthFlow(final ConfigRepository configRepository, final HttpClient httpClient, final Supplier<String> stateSupplier) { | ||
super(configRepository, httpClient, stateSupplier); | ||
this.clock = Clock.systemUTC(); | ||
} | ||
|
||
public GitlabOAuthFlow(final ConfigRepository configRepository, final HttpClient httpClient, final Supplier<String> stateSupplier, Clock clock) { | ||
super(configRepository, httpClient, stateSupplier); | ||
this.clock = clock; | ||
} | ||
|
||
protected static String getDomain(JsonNode inputOAuthConfiguration) throws IOException { | ||
final var domain = inputOAuthConfiguration.get("domain"); | ||
if (domain == null) { | ||
throw new IOException("Domain field is empty."); | ||
} | ||
return domain.asText(); | ||
} | ||
|
||
@Override | ||
protected String formatConsentUrl(final UUID definitionId, final String clientId, final String redirectUrl, final JsonNode inputOAuthConfiguration) | ||
throws IOException { | ||
final URIBuilder builder = new URIBuilder() | ||
.setScheme("https") | ||
.setHost(getDomain(inputOAuthConfiguration)) | ||
.setPath("oauth/authorize") | ||
.addParameter("client_id", clientId) | ||
.addParameter("redirect_uri", redirectUrl) | ||
.addParameter("state", getState()) | ||
.addParameter("response_type", "code") | ||
.addParameter("scope", "read_api"); | ||
try { | ||
return builder.build().toString(); | ||
} catch (URISyntaxException e) { | ||
throw new IOException("Failed to format Consent URL for OAuth flow", e); | ||
} | ||
} | ||
|
||
@Override | ||
protected String getAccessTokenUrl(final JsonNode inputOAuthConfiguration) { | ||
final var domain = inputOAuthConfiguration.get("domain"); | ||
return String.format(ACCESS_TOKEN_URL, domain == null ? "gitlab.com" : domain.asText()); | ||
} | ||
|
||
@Override | ||
protected Map<String, String> getAccessTokenQueryParameters(final String clientId, | ||
final String clientSecret, | ||
final String authCode, | ||
final String redirectUrl) { | ||
return ImmutableMap.<String, String>builder() | ||
.put("client_id", clientId) | ||
.put("client_secret", clientSecret) | ||
.put("code", authCode) | ||
.put("grant_type", "authorization_code") | ||
.put("redirect_uri", redirectUrl) | ||
.build(); | ||
} | ||
|
||
@Override | ||
protected Map<String, Object> extractOAuthOutput(final JsonNode data, final String accessTokenUrl) throws IOException { | ||
final Map<String, Object> result = new HashMap<>(); | ||
if (data.has("refresh_token")) { | ||
result.put("refresh_token", data.get("refresh_token").asText()); | ||
} else { | ||
throw new IOException(String.format("Missing 'refresh_token' in query params from %s", accessTokenUrl)); | ||
} | ||
if (data.has("access_token")) { | ||
result.put("access_token", data.get("access_token").asText()); | ||
} else { | ||
throw new IOException(String.format("Missing 'access_token' in query params from %s", accessTokenUrl)); | ||
} | ||
if (data.has("expires_in")) { | ||
Instant expires_in = Instant.now(this.clock).plusSeconds(data.get("expires_in").asInt()); | ||
result.put("token_expiry_date", expires_in.toString()); | ||
} else { | ||
throw new IOException(String.format("Missing 'expires_in' in query params from %s", accessTokenUrl)); | ||
} | ||
return result; | ||
} | ||
|
||
@Override | ||
@Deprecated | ||
public Map<String, Object> completeSourceOAuth(final UUID workspaceId, | ||
final UUID sourceDefinitionId, | ||
final Map<String, Object> queryParams, | ||
final String redirectUrl) | ||
throws IOException, ConfigNotFoundException { | ||
throw new IOException("Deprecated API not supported by this connector"); | ||
} | ||
|
||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.