···
1
-
import 'package:atproto_oauth_flutter/atproto_oauth_flutter.dart';
3
-
import 'environment_config.dart';
5
-
/// OAuth Configuration for atProto
1
+
/// OAuth Configuration for Coves Backend OAuth
7
-
/// This configuration provides ClientMetadata for the new
8
-
/// atproto_oauth_flutter package. The new package handles proper
9
-
/// decentralized OAuth discovery (works with ANY PDS).
3
+
/// This configuration supports the backend's mobile OAuth flow.
4
+
/// The backend handles all OAuth complexity (PKCE, DPoP, token exchange).
6
+
/// Uses private-use URI scheme per atproto spec (RFC 8252):
7
+
/// - Format: social.coves:/callback (single slash!)
8
+
/// - Works on both Android and iOS without Universal Links complexity
11
-
// OAuth Server Configuration
12
-
// Cloudflare Worker that hosts client-metadata.json and handles OAuth
14
-
static const String oauthServerUrl =
15
-
'https://lingering-darkness-50a6.brettmay0212.workers.dev';
// Custom URL scheme for deep linking
18
-
// Must match AndroidManifest.xml intent filters
19
-
// Using the same format as working Expo implementation
20
-
static const String customScheme =
21
-
'dev.workers.brettmay0212.lingering-darkness-50a6';
11
+
// Must match AndroidManifest.xml and Info.plist
12
+
// Uses reverse domain format per atproto spec
13
+
static const String customScheme = 'social.coves';
23
-
// API Configuration
24
-
// Environment-aware API URL
25
-
static String get apiUrl => EnvironmentConfig.current.apiUrl;
15
+
// Redirect URI using private-use URI scheme (RFC 8252)
16
+
// IMPORTANT: Single slash after scheme per RFC 8252!
17
+
static const String _redirectUri = '$customScheme:/callback';
27
-
// Derived OAuth URLs
28
-
static const String clientId = '$oauthServerUrl/client-metadata.json';
19
+
/// Get the redirect URI (same for all environments)
20
+
static String get redirectUri => _redirectUri;
30
-
// IMPORTANT: Private-use URI schemes (RFC 8252) require SINGLE slash,
32
-
// Correct: dev.workers.example:/oauth/callback
33
-
// Incorrect: dev.workers.example://oauth/callback
34
-
static const String customSchemeCallback = '$customScheme:/oauth/callback';
36
-
// HTTPS callback (fallback for PDS that don't support custom
38
-
static const String httpsCallback = '$oauthServerUrl/oauth/callback';
22
+
/// Get the callback scheme for FlutterWebAuth2
23
+
static String get callbackScheme => customScheme;
// OAuth Scopes - recommended scope for atProto
static const String scope = 'atproto transition:generic';
// Client name for display during authorization
static const String clientName = 'Coves';
46
-
/// Create ClientMetadata for the FlutterOAuthClient
48
-
/// This configures the OAuth client with:
49
-
/// - Discoverable client ID (HTTPS URL to metadata JSON)
50
-
/// - HTTPS callback (primary - works with all PDS servers)
51
-
/// - Custom URL scheme (fallback - requires PDS support)
52
-
/// - DPoP enabled for token security
53
-
/// - Proper scopes for atProto access
54
-
static ClientMetadata createClientMetadata() {
55
-
return const ClientMetadata(
57
-
// Use HTTPS as PRIMARY - prevents browser re-navigation that
58
-
// invalidates auth codes. Custom scheme as fallback (Worker page
59
-
// redirects to custom scheme anyway)
60
-
redirectUris: [httpsCallback, customSchemeCallback],
62
-
clientName: clientName,
63
-
dpopBoundAccessTokens: true, // Enable DPoP for security
64
-
applicationType: 'native',
65
-
grantTypes: ['authorization_code', 'refresh_token'],
66
-
tokenEndpointAuthMethod: 'none', // Public client (mobile apps)