Skip to content

Commit 8ab97e0

Browse files
feat: add example
Signed-off-by: The one with the braid <[email protected]>
1 parent 34ab897 commit 8ab97e0

File tree

1 file changed

+56
-0
lines changed
  • lib/msc_extensions/msc_3861_native_oidc

1 file changed

+56
-0
lines changed
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
# Implement \[matrix\] OIDC using the Matrix Dart SDK
2+
3+
```dart
4+
import 'dart:async';
5+
6+
import 'package:flutter/foundation.dart';
7+
8+
import 'package:matrix/matrix.dart';
9+
import 'package:url_launcher:url_launcher.dart';
10+
11+
Future<void> main() async {
12+
final client = Client(
13+
// [...]
14+
);
15+
16+
await client.checkHomeserver(myHomeserver);
17+
18+
final name = 'My [matrix] client on web';
19+
20+
final registrationData = OidcDynamicRegistrationData.localized(
21+
contacts: {myOidcAdminContact},
22+
url: 'https://example.com',
23+
defaultLocale: myDefaultLocale,
24+
localizations: {
25+
'fr_FR': LocalizedOidcClientMetadata(
26+
// [...]
27+
)
28+
},
29+
redirect: kIsWeb
30+
? { 'http://localhost:0'}
31+
: {
32+
Uri.parse('com.example:/oauth2redirect/'),
33+
Uri.parse('http://localhost/oauth2redirect/'),
34+
},
35+
applicationType: kIsWeb ? 'web' : 'native',
36+
);
37+
38+
final oidcClientId = await client.oidcEnsureDynamicClientId(
39+
registrationData,
40+
);
41+
42+
// You can e.g. use `package:app_links` to forward the called deep link into this completer
43+
final nativeCompleter = Completer<OidcCallbackResponse>();
44+
45+
await client.oidcAuthorizationGrantFlow(
46+
nativeCompleter: nativeCompleter,
47+
oidcClientId: oidcClientId,
48+
redirectUri: client.oAuth2RedirectUri,
49+
launchOAuth2Uri: launchUrl,
50+
responseMode: kIsWeb ? 'fragment' : 'query',
51+
prompt: 'consent',
52+
initialDeviceDisplayName: name,
53+
enforceNewDeviceId: true,
54+
);
55+
}
56+
```

0 commit comments

Comments
 (0)