I’m having trouble with Notion’s OAuth in my Flutter app. The API only works with https:// redirect URLs. I tried using Flutter Custom Tabs and Firebase Dynamic Links, but it’s not working as expected.
My setup:
- Dynamic link: myappname.page.link/start
- Deep link: myappname.page.link
The problem is Notion should add parameters to the redirect URL, like myappname.net?code=xxx. But my app only gets the basic URL without any extras.
I’ve looked into it and found out Firebase Dynamic Links can’t be customized for this. Does anyone know a different way to catch the OAuth response in a Flutter app without using Dynamic Links? I’m out of ideas and could use some help!
hey mate, have u tried using the app_links package? it’s pretty neat for handling deep links in flutter apps. just set up a custom url scheme like ‘myapp://’ and configure notion to redirect there. the package catches the full url with all the params, so u can grab that oauth code easily. no need for firebase or https stuff. give it a shot!
Have you considered using the uni_links package for handling deep links in Flutter? It’s a robust solution that works well with OAuth flows. Here’s a quick rundown:
- Add uni_links to your dependencies.
- Set up a custom URL scheme for your app.
- Configure your Notion OAuth redirect URI to use this scheme.
- Use uni_links to listen for incoming links in your app.
When Notion redirects back to your app, uni_links will capture the full URL with all parameters. You can then extract the OAuth code and proceed with token exchange.
This method bypasses the need for https:// URLs and works seamlessly across platforms. It’s been reliable in my projects dealing with various OAuth providers, including Notion.
Remember to properly configure your AndroidManifest.xml and Info.plist to handle the custom URL scheme. This approach should resolve your parameter capturing issue without relying on Dynamic Links.
I’ve faced similar challenges with OAuth in Flutter, and I can share what worked for me. Instead of using Firebase Dynamic Links, I found success with the flutter_web_auth package. It provides a more straightforward way to handle OAuth flows in Flutter apps.
Here’s how I implemented it:
- Add flutter_web_auth to your pubspec.yaml
- Set up a custom URL scheme for your app (e.g., myapp://)
- Use flutter_web_auth.authenticate() to open the Notion OAuth URL
- Set your redirect URI to your custom scheme (e.g., myapp://oauth/callback)
- The package will automatically capture the full redirect URL with all parameters
This approach solved the https:// requirement and parameter capturing issues for me. It’s a bit more work to set up initially, but it’s more reliable and gives you full control over the OAuth flow. Remember to update your app’s URL schemes in the iOS and Android project settings too.
Hope this helps you get unstuck!