Skip to content
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

add OAuth 2.0 for microsoft_teams source connector #7807

Merged
merged 36 commits into from
Dec 13, 2021
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
d65eddc
add OAuth 2.0 for microsoft_teams source connector
grubberr Nov 10, 2021
8c87b42
Merge branch 'master' into grubberr/7704-source-microsoft-teams
grubberr Nov 10, 2021
7f28921
bump version 0.2.2 -> 0.2.3
grubberr Nov 10, 2021
b5f9825
authSpecification added
grubberr Nov 10, 2021
dade790
Merge branch 'master' into grubberr/7704-source-microsoft-teams
grubberr Nov 10, 2021
76a64e6
MicrosoftTeamsOAuthFlow.java added
grubberr Nov 10, 2021
d8403ff
Merge branch 'master' into grubberr/7704-source-microsoft-teams
grubberr Nov 10, 2021
6ed96f5
getScopes added
grubberr Nov 10, 2021
942260a
Merge branch 'master' into grubberr/7704-source-microsoft-teams
grubberr Nov 13, 2021
8e61a41
Merge branch 'master' into grubberr/7704-source-microsoft-teams
grubberr Nov 13, 2021
55b8b84
Merge branch 'master' into grubberr/7704-source-microsoft-teams
grubberr Nov 18, 2021
6d37423
fix formatConsentUrl
grubberr Nov 18, 2021
13b320b
Merge branch 'master' into grubberr/7704-source-microsoft-teams
grubberr Nov 25, 2021
8f68634
lint code
grubberr Nov 25, 2021
42bd078
Merge branch 'master' into grubberr/7704-source-microsoft-teams
grubberr Dec 7, 2021
02fec68
bump version 0.2.3 -> 0.2.4
grubberr Dec 7, 2021
f8c7ab7
Merge branch 'master' into grubberr/7704-source-microsoft-teams
grubberr Dec 8, 2021
1dc07be
spec.json updated
grubberr Dec 8, 2021
82ac267
old_config.json, config_oauth.json added
grubberr Dec 8, 2021
05d227c
make self.msal_app lazy
grubberr Dec 8, 2021
6e505c7
bugfix
grubberr Dec 8, 2021
8ae29ce
getSourceConsentUrl added
grubberr Dec 8, 2021
35e22ed
Merge branch 'master' into grubberr/7704-source-microsoft-teams
grubberr Dec 9, 2021
2c68c3f
bugfix move tenant_id -> "oauth_user_input_from_connector_config_spec…
grubberr Dec 9, 2021
9842438
Revert "getSourceConsentUrl added"
grubberr Dec 9, 2021
23fff99
Merge branch 'master' into grubberr/7704-source-microsoft-teams
grubberr Dec 10, 2021
8f9251a
get tenantId from 'inputOAuthConfiguration'
grubberr Dec 10, 2021
3320fd2
Merge branch 'master' into grubberr/7704-source-microsoft-teams
grubberr Dec 12, 2021
5c28fe6
MicrosoftTeamsOAuthFlow.java improved
grubberr Dec 12, 2021
efb1851
MicrosoftTeamsOAuthFlowTest.java added
grubberr Dec 12, 2021
046decb
Merge branch 'master' into grubberr/7704-source-microsoft-teams
grubberr Dec 13, 2021
fde20a8
pass inputOAuthConfiguration to getAccessTokenUrl method
grubberr Dec 13, 2021
c09d965
lint code
grubberr Dec 13, 2021
0394383
improve 'not supported' message
grubberr Dec 13, 2021
5475a43
Merge branch 'master' into grubberr/7704-source-microsoft-teams
grubberr Dec 13, 2021
430e442
source_specs.yaml updated
grubberr Dec 13, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,7 @@ public Map<String, Object> completeSourceOAuth(final UUID workspaceId,
getClientSecretUnsafe(oAuthParamConfig),
extractCodeParameter(queryParams),
redirectUrl,
Jsons.emptyObject(),
oAuthParamConfig),
getDefaultOAuthOutputPath());
}
Expand All @@ -162,6 +163,7 @@ public Map<String, Object> completeDestinationOAuth(final UUID workspaceId,
getClientSecretUnsafe(oAuthParamConfig),
extractCodeParameter(queryParams),
redirectUrl,
Jsons.emptyObject(),
oAuthParamConfig),
getDefaultOAuthOutputPath());
}
Expand All @@ -183,6 +185,7 @@ public Map<String, Object> completeSourceOAuth(final UUID workspaceId,
getClientSecretUnsafe(oAuthParamConfig),
extractCodeParameter(queryParams),
redirectUrl,
inputOAuthConfiguration,
oAuthParamConfig),
oAuthConfigSpecification);
}
Expand All @@ -204,6 +207,7 @@ public Map<String, Object> completeDestinationOAuth(final UUID workspaceId,
getClientSecretUnsafe(oAuthParamConfig),
extractCodeParameter(queryParams),
redirectUrl,
inputOAuthConfiguration,
oAuthParamConfig),
oAuthConfigSpecification);
}
Expand All @@ -212,9 +216,10 @@ protected Map<String, Object> completeOAuthFlow(final String clientId,
final String clientSecret,
final String authCode,
final String redirectUrl,
final JsonNode inputOAuthConfiguration,
final JsonNode oAuthParamConfig)
throws IOException {
final var accessTokenUrl = getAccessTokenUrl();
final var accessTokenUrl = getAccessTokenUrl(inputOAuthConfiguration);
final HttpRequest request = HttpRequest.newBuilder()
.POST(HttpRequest.BodyPublishers
.ofString(tokenReqContentType.converter.apply(getAccessTokenQueryParameters(clientId, clientSecret, authCode, redirectUrl))))
Expand Down Expand Up @@ -263,7 +268,7 @@ protected String extractCodeParameter(final Map<String, Object> queryParams) thr
/**
* Returns the URL where to retrieve the access token from.
*/
protected abstract String getAccessTokenUrl();
protected abstract String getAccessTokenUrl(final JsonNode inputOAuthConfiguration);

/**
* Extract all OAuth outputs from distant API response and store them in a flat map.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ protected String formatConsentUrl(final UUID definitionId,
}

@Override
protected String getAccessTokenUrl() {
protected String getAccessTokenUrl(final JsonNode inputOAuthConfiguration) {
return ACCESS_TOKEN_URL;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ protected String extractCodeParameter(Map<String, Object> queryParams) throws IO
}

@Override
protected String getAccessTokenUrl() {
protected String getAccessTokenUrl(final JsonNode inputOAuthConfiguration) {
return ACCESS_TOKEN_URL;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ protected String formatConsentUrl(final UUID definitionId,
}

@Override
protected String getAccessTokenUrl() {
protected String getAccessTokenUrl(final JsonNode inputOAuthConfiguration) {
return ACCESS_TOKEN_URL;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ protected Map<String, String> getAccessTokenQueryParameters(final String clientI
*
*/
@Override
protected String getAccessTokenUrl() {
protected String getAccessTokenUrl(final JsonNode inputOAuthConfiguration) {
return ACCESS_TOKEN_URL;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ private String getScopes() {
*
*/
@Override
protected String getAccessTokenUrl() {
protected String getAccessTokenUrl(final JsonNode inputOAuthConfiguration) {
return "https://api.hubapi.com/oauth/v1/token";
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ protected String formatConsentUrl(final UUID definitionId,
}

@Override
protected String getAccessTokenUrl() {
protected String getAccessTokenUrl(final JsonNode inputOAuthConfiguration) {
return ACCESS_TOKEN_URL;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ protected String formatConsentUrl(UUID definitionId,
}

@Override
protected String getAccessTokenUrl() {
protected String getAccessTokenUrl(final JsonNode inputOAuthConfiguration) {
return ACCESS_TOKEN_URL;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
public class MicrosoftTeamsOAuthFlow extends BaseOAuth2Flow {

private static final String fieldName = "tenant_id";
private static String tenantId;

public MicrosoftTeamsOAuthFlow(final ConfigRepository configRepository, final HttpClient httpClient) {
super(configRepository, httpClient);
Expand All @@ -48,6 +47,7 @@ protected String formatConsentUrl(final UUID definitionId,
final JsonNode inputOAuthConfiguration)
throws IOException {

String tenantId;
grubberr marked this conversation as resolved.
Show resolved Hide resolved
try {
tenantId = getConfigValueUnsafe(inputOAuthConfiguration, fieldName);
} catch (final IllegalArgumentException e) {
Expand Down Expand Up @@ -129,46 +129,13 @@ public Map<String, Object> completeDestinationOAuth(final UUID workspaceId,
throw new IOException("not supported");
grubberr marked this conversation as resolved.
Show resolved Hide resolved
}

@Override
public Map<String, Object> completeSourceOAuth(final UUID workspaceId,
final UUID sourceDefinitionId,
final Map<String, Object> queryParams,
final String redirectUrl,
final JsonNode inputOAuthConfiguration,
final OAuthConfigSpecification oAuthConfigSpecification)
throws IOException, ConfigNotFoundException, JsonValidationException {
tenantId = null;
try {
tenantId = getConfigValueUnsafe(inputOAuthConfiguration, fieldName);
} catch (final IllegalArgumentException e) {}
return super.completeSourceOAuth(workspaceId, sourceDefinitionId, queryParams, redirectUrl, inputOAuthConfiguration, oAuthConfigSpecification);
}

@Override
public Map<String, Object> completeDestinationOAuth(final UUID workspaceId,
final UUID destinationDefinitionId,
final Map<String, Object> queryParams,
final String redirectUrl,
final JsonNode inputOAuthConfiguration,
final OAuthConfigSpecification oAuthConfigSpecification)
throws IOException, ConfigNotFoundException, JsonValidationException {
tenantId = null;
try {
tenantId = getConfigValueUnsafe(inputOAuthConfiguration, fieldName);
} catch (final IllegalArgumentException e) {}
return super.completeDestinationOAuth(workspaceId, destinationDefinitionId, queryParams, redirectUrl, inputOAuthConfiguration,
oAuthConfigSpecification);
}

/**
* Returns the URL where to retrieve the access token from.
*
*/
@Override
protected String getAccessTokenUrl() {
if (tenantId == null) {
throw new IllegalArgumentException(String.format("Undefined parameter '%s' necessary for the OAuth Flow.", fieldName));
}
protected String getAccessTokenUrl(final JsonNode inputOAuthConfiguration) {
String tenantId = getConfigValueUnsafe(inputOAuthConfiguration, fieldName);
grubberr marked this conversation as resolved.
Show resolved Hide resolved
return "https://login.microsoftonline.com/" + tenantId + "/oauth2/v2.0/token";
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ protected Map<String, String> getAccessTokenQueryParameters(final String clientI
}

@Override
protected String getAccessTokenUrl() {
protected String getAccessTokenUrl(final JsonNode inputOAuthConfiguration) {
return ACCESS_TOKEN_URL;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ protected Map<String, String> getAccessTokenQueryParameters(final String clientI
* Returns the URL where to retrieve the access token from.
*/
@Override
protected String getAccessTokenUrl() {
protected String getAccessTokenUrl(final JsonNode inputOAuthConfiguration) {
return TOKEN_URL;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ protected Map<String, String> getAccessTokenQueryParameters(final String clientI
*
*/
@Override
protected String getAccessTokenUrl() {
protected String getAccessTokenUrl(final JsonNode inputOAuthConfiguration) {
return ACCESS_TOKEN_URL;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ protected String formatConsentUrl(final UUID definitionId,
}

@Override
protected String getAccessTokenUrl() {
protected String getAccessTokenUrl(final JsonNode inputOAuthConfiguration) {
return ACCESS_TOKEN_URL;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ protected String formatConsentUrl(final UUID definitionId,
* Returns the URL where to retrieve the access token from.
*/
@Override
protected String getAccessTokenUrl() {
protected String getAccessTokenUrl(final JsonNode inputOAuthConfiguration) {
return SLACK_TOKEN_URL;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ protected String formatConsentUrl(final UUID definitionId,
}

@Override
protected String getAccessTokenUrl() {
protected String getAccessTokenUrl(final JsonNode inputOAuthConfiguration) {
return ACCESS_TOKEN_URL;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ protected String formatConsentUrl(final UUID definitionId,
}

@Override
protected String getAccessTokenUrl() {
protected String getAccessTokenUrl(final JsonNode inputOAuthConfiguration) {
return ACCESS_TOKEN_URL;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ protected String formatConsentUrl(final UUID definitionId,
}

@Override
protected String getAccessTokenUrl() {
protected String getAccessTokenUrl(final JsonNode inputOAuthConfiguration) {
return ACCESS_TOKEN_URL;
}

Expand All @@ -76,6 +76,7 @@ protected Map<String, Object> completeOAuthFlow(final String clientId,
final String clientSecret,
final String authCode,
final String redirectUrl,
final JsonNode inputOAuthConfiguration,
final JsonNode oAuthParamConfig)
throws IOException {
// Access tokens generated via web login are short-lived tokens
Expand All @@ -84,7 +85,7 @@ protected Map<String, Object> completeOAuthFlow(final String clientId,
// https://developers.facebook.com/docs/instagram-basic-display-api/overview#short-lived-access-tokens
// Long-Term Tokens section)

final Map<String, Object> data = super.completeOAuthFlow(clientId, clientSecret, authCode, redirectUrl, oAuthParamConfig);
final Map<String, Object> data = super.completeOAuthFlow(clientId, clientSecret, authCode, redirectUrl, inputOAuthConfiguration, oAuthParamConfig);
Preconditions.checkArgument(data.containsKey("access_token"));
final String shortLivedAccessToken = (String) data.get("access_token");
final String longLivedAccessToken = getLongLivedAccessToken(clientId, clientSecret, shortLivedAccessToken);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ protected String formatConsentUrl(final UUID definitionId,
protected abstract String getScope();

@Override
protected String getAccessTokenUrl() {
protected String getAccessTokenUrl(final JsonNode inputOAuthConfiguration) {
return ACCESS_TOKEN_URL;
}

Expand Down