startOAuthInstall method
Starts an OAuth install for Slack or Notion.
Returns the authorize URL the UI should launch in the external browser. For Lucca (which has no browser redirect), use installLuccaClientCredentials instead.
When clientId / clientSecret are provided they are stored
encrypted as per-org BYO credentials. When both are null the Edge
Function falls back to the {PROVIDER}_CLIENT_ID /
{PROVIDER}_CLIENT_SECRET project secrets (hosted-demo convenience).
Implementation
Future<Uri> startOAuthInstall({
required String orgId,
required String provider,
String? clientId,
String? clientSecret,
}) async {
assert(provider == 'slack' || provider == 'notion');
final response = await _client.functions.invoke(
'integrations-oauth-start',
body: {
'org_id': orgId,
'provider': provider,
'client_id': ?clientId,
'client_secret': ?clientSecret,
},
);
if (response.status != 200) {
throw StateError(
'startOAuthInstall failed (${response.status}): ${response.data}',
);
}
final url = response.data?['authorize_url'] as String?;
if (url == null || url.isEmpty) {
throw StateError('startOAuthInstall returned no authorize_url');
}
return Uri.parse(url);
}