Hello! I am currently working on a project where w...
# airbyte-api
j
Hello! I am currently working on a project where we have to create a larger number of connections for the same source connector. I have a number of facebook ad accounts that I want to integrate. All ad accounts are connected to a single facebook account. I thought about using the Airbyte API to automate the creation. My understanding so far is that I will have to initiate an oath flow via the
<https://api.airbyte.com/v1/sources/initiateOAuth>
endpoint which will give me a
secretId
that I can then use to create the connection. I am hoping that I might only have to go through this once and re-use the secret ID given all ad accounts are authorized via the same facebook account. However, I am having issues with setting the correct redirect URL, given I am not running any app from which I will be able to accept the response from the flow. Is there a way to redirect my call to something local or to an airbyte hosted page? The docs specify https://cloud.airbyte.io/v1/api/oauth/callback as an example but that doesn't seem to work.
I've tried the following so far:
Copy code
import airbyte
from airbyte.models import shared

s = airbyte.Airbyte(
    security=shared.Security(
        bearer_auth="Bearer xxx",
    ),
)


req = shared.InitiateOauthRequest(
    name="facebook-marketing",
    o_auth_input_configuration={
    },
    redirect_url="<https://cloud.airbyte.io/v1/api/oauth/callback>",
    workspace_id="aaaa-bbbb-cccc",
)

res = s.sources.initiate_o_auth(req)

print(res.raw_response.json())
The response is:
Copy code
{'consentUrl': '<https://www.facebook.com/v12.0/dialog/oauth?client_id=600551260845577&redirect_uri=https%3A%2F%2Fapi.airbyte.com%2Fv1%2Foauth%2Fcallback&state=BmCU1AZ&scope=ads_management%2Cads_read%2Cread_insights%2Cbusiness_management>'}
It's interesting that the
redirect_uri
param of the url remains the same no matter my input in the request. Is the client_id specified the client id of the airbyte app? When clicking on the Link, I get "*URL blocked* This redirect failed because the redirect URI is not white-listed in the app's client OAuth settings. Make sure that the client and web OAuth logins are on and add all your app domains as valid OAuth redirect URIs."
b
The redirect URL is used to land the user after the consent flow. So this needs to be a URL to a server that you control. You can use localhost, but currently we only support https as a protocol. You should be able to use a self signed certificate. We can probably relax the https requirement for localhost as well. @Jon Tan (Airbyte)
j
Hi @Bryce Groff (Airbyte), thanks for looking into this. Did you change something to the airbyte Facebook app? The above link is now properly returning without the URL allow-list error
j
Sorry I was going to respond to this thread - we did indeed make a change on our end to enable this. We're working on making sure all of the OAuth sources are enabled through the public API. If you run into a similar error, please let us know and we can most likely resolve the issue or investigate. Appreciate you bringign this to our attention.
j
great, thanks a lot! I was now able to create a connection in the UI with the source created via the API. I will continue my testing tomorrow (building destination and connection via the API) and let you know if anything else comes up. I appreciate the quick response here 🙂
j
@Jon Tan (Airbyte) Sorry I couldn’t find other threads around the
<https://api.airbyte.com/v1/sources/initiateOAuth>
endpoint so I’m reviving this. As mentioned in the thread, the
redirect_url
set in the request does not impact the
redirect_uri
in the resulting
consent_url
. As an example, when invoking Notion’s OAuth flow via
Copy code
curl --request POST \
     --url <https://api.airbyte.com/v1/sources/initiateOAuth> \
     --header 'accept: application/json' \
     --header 'authorization: Bearer <TOKEN>' \
     --header 'content-type: application/json' \
     --data '
{
  "name": "notion",
  "redirectUrl": "https://<DOMAIN>.com",
  "workspaceId": "<ID>"
}
I get the following response,
Copy code
{
  "consentUrl": "<https://api.notion.com/v1/oauth/authorize?client_id=><ID>&response_type=code&redirect_uri=https%3A%2F%2Fapi.airbyte.com%2Fv1%2Foauth%2Fcallback&state=<STATE>"
}
The link prompts an error (See screenshot). If I update the
redirect_uri
to
https%3A%2F%<http://2Fcloud.airbyte.com|2Fcloud.airbyte.com>%2Fauth_flow
, I get the right OAuth flow. So curious to know what I’m doing wrong here. Thanks for the help!
j
@Jensen Kuo You’re correct that the redirect URL passed does not affect the consent redirect URL. The URL you pass us is the URL you want us to redirect your user to. The URL used for the OAuth flow is Airbyte’s OAuth URL so we can handle the token exchange/secret storage for you. In this case, the reason things aren’t working as expected is because we’ve been allowlisting the new OAuth callback as users have been requesting access to different sources. I’ll update the notion callback URLs on our end and let you know when you should be able to go through the flow again
j
@Jon Tan (Airbyte) Thanks for the update. Could I get an ETA for this? Would be great to get this working so we don’t have to do OAuth override on our end.
j
Hey Jensen. Hoping to get this resolved this week.