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

Instagram oAuth backend #7412

Merged
merged 5 commits into from
Oct 29, 2021
Merged

Instagram oAuth backend #7412

merged 5 commits into from
Oct 29, 2021

Conversation

avida
Copy link
Contributor

@avida avida commented Oct 27, 2021

What

Resolves #7115

@avida avida temporarily deployed to more-secrets October 27, 2021 13:41 Inactive
return Map.of("access_token", longLivedAccessToken);
}

private String getLongLivedAccessToken(final String clientId, final String clientSecret, final String shortLivedAccessToken) throws IOException {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't this be DRY with the instagram one?

Opportunity to introduce a FacebookOAuthFlow that factors the process for facebook related connectors?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

@avida avida requested a review from ChristopheDuong October 28, 2021 09:28
@avida avida temporarily deployed to more-secrets October 28, 2021 09:29 Inactive
.put("airbyte/source-github", new GithubOAuthFlow(configRepository))
.put("airbyte/source-google-ads", new GoogleAdsOAuthFlow(configRepository))
.put("airbyte/source-google-analytics-v4", new GoogleAnalyticsOAuthFlow(configRepository))
.put("airbyte/source-google-search-console", new GoogleSearchConsoleOAuthFlow(configRepository))
.put("airbyte/source-google-sheets", new GoogleSheetsOAuthFlow(configRepository))
// Instagram connector use Facebook Marketing API
.put("airbyte/source-instagram", new FacebookOAuthFlow(configRepository))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this be instead?

Suggested change
.put("airbyte/source-instagram", new FacebookOAuthFlow(configRepository))
.put("airbyte/source-instagram", new InstagramOAuthFlow(configRepository))

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, see comment above

// Instagram connector use Facebook Marketing API

I figured it out when I started doing e2e test, so I commited InstagramOAuthFlow just in case we will need it in future.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we switch to InstagramOAuthFlow here even if the implementation is exactly the same?

So if, in the future, there's actual implementation differences, we wouldn't even need to change the mapping in the factory?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The factory should point to specific concrete implementation as i commented here https://github.com/airbytehq/airbyte/pull/7412/files#r738454432

and we try to move as much code as possible in the common abstract class

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we switch to InstagramOAuthFlow here even if the implementation is exactly the same?

No, cause Instagram connector use Facebook Marketing API, it wouldnt work with InstagramOAuthFlow class. Ive figured it out after Ive done work on InstagramOAuthFlow so just added it to PR in case we going to need it in the future.
InstagramOAuthFlow has different auth workflow and generates token that doesnt work with facebook marketing API.

Copy link
Contributor

@ChristopheDuong ChristopheDuong Oct 28, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Then that's very confusing and it is probably worth making it more visible in the code...

What about renaming InstagramOAuthFlow to UnusedInstagramOAuthFlow or InstagramAPIOAuthFlow instead and explains in a comment why it is there.

Then we should have an InstagramOAuthFlow that extends the FacebookOAuthFlow just like how FacebookMarketingOAuthFlow does now.

Or should we have an InstagramWithFacebookMarketingApiOAuthFlow class?

The factory would map source-instagram to InstagramOAuthFlow without surprises and we can switch the behavior / implementation of the class in the future without ever touching the factory

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instagram connector use Facebook Marketing API
InstagramOAuthFlow has different auth workflow and generates token that doesnt work with facebook marketing API.

If i follow here, the source-instagram connector is implemented to pull instagram data from FacebookMarketingAPi.

If source-instagram connector is refactored to use the pure instagram API, then it would need a different oauthflow implementation

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if Instagram oauth flow is unused imo we should remove it from the code

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Then we should have an InstagramOAuthFlow that extends the FacebookOAuthFlow just like how FacebookMarketingOAuthFlow does now.

Done

if Instagram oauth flow is unused imo we should remove it from the code

Removed it

@Override
protected String formatConsentUrl(final UUID definitionId, final String clientId, final String redirectUrl) throws IOException {
try {
return new URIBuilder(AUTHORIZE_URL)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the only difference here for Instagram from the super.formatConsentUrl from Facebook flow is the AUTHORIZE_URL?

Can't we just override a getAuthorizeUrl method and keep the rest DRY?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, they have different grant_type and parameters list (for instagram you dont need client secret and response_type parameters)

@avida avida requested a review from ChristopheDuong October 28, 2021 14:23
@avida avida temporarily deployed to more-secrets October 28, 2021 14:24 Inactive
* Following docs from
* https://developers.facebook.com/docs/facebook-login/manually-build-a-login-flow
*/
public class FacebookMarketingOAuthFlow extends BaseOAuthFlow {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we keep FacebookMarketingOAuthFlow extends FacebookOAuthFlow

And we define the getScope method in here and leave it as abstract in FacebookOAuthFlow?

Every facebook connector would have to re-implement a concrete class where the getScope or whatever method that differ slightly would be overriden

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

@avida avida temporarily deployed to more-secrets October 28, 2021 15:29 Inactive
@avida avida requested a review from ChristopheDuong October 28, 2021 15:31
@avida avida temporarily deployed to more-secrets October 29, 2021 07:43 Inactive
Copy link
Contributor

@sherifnada sherifnada left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

so. damn. clean.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

oAuth backend for instagram source
4 participants