Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 46 additions & 8 deletions flutter_appauth/example/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import 'dart:convert';
import 'dart:io' show Platform;
import 'dart:math';

import 'package:flutter/foundation.dart' show kIsWeb;
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter_appauth/flutter_appauth.dart';
Expand All @@ -28,6 +29,38 @@ class _MyAppState extends State<MyApp> {
String? _idToken;
String? _error;

@override
void initState() {
super.initState();
if (kIsWeb) {
_checkForPendingAuthorization();
}
}

Future<void> _checkForPendingAuthorization() async {
await Future.delayed(const Duration(milliseconds: 100));

setState(() {
_isBusy = true;
});

try {
final result = await _appAuth.authorizeAndExchangeCode(
AuthorizationTokenRequest(_clientId, _redirectUrl,
serviceConfiguration: _serviceConfiguration,
scopes: _scopes),
);
_processAuthTokenResponse(result);
await _testApi(result);
} catch (e) {
if (!e.toString().contains('authorization_in_progress')) {
_handleError(e);
}
} finally {
_clearBusyState();
}
}

final TextEditingController _authorizationCodeTextController =
TextEditingController();
final TextEditingController _accessTokenTextController =
Expand All @@ -40,13 +73,16 @@ class _MyAppState extends State<MyApp> {
TextEditingController();
String? _userInfo;

// For a list of client IDs, go to https://demo.duendesoftware.com
final String _clientId = 'interactive.public';
final String _redirectUrl = 'com.duendesoftware.demo:/oauthredirect';
final String _redirectUrl = kIsWeb
? 'http://localhost:8080/'
: 'com.duendesoftware.demo:/oauthredirect';
final String _issuer = 'https://demo.duendesoftware.com';
final String _discoveryUrl =
'https://demo.duendesoftware.com/.well-known/openid-configuration';
final String _postLogoutRedirectUrl = 'com.duendesoftware.demo:/';
final String _postLogoutRedirectUrl = kIsWeb
? 'http://localhost:8080/'
: 'com.duendesoftware.demo:/';
final List<String> _scopes = <String>[
'openid',
'profile',
Expand Down Expand Up @@ -96,9 +132,11 @@ class _MyAppState extends State<MyApp> {
const SizedBox(height: 8),
ElevatedButton(
child: const Text('Sign in with auto code exchange'),
onPressed: () => _signInWithAutoCodeExchange(),
onPressed: () {
_signInWithAutoCodeExchange();
},
),
if (Platform.isIOS || Platform.isMacOS)
if (!kIsWeb && (Platform.isIOS || Platform.isMacOS))
Padding(
padding: const EdgeInsets.all(8.0),
child: ElevatedButton(
Expand All @@ -112,7 +150,7 @@ class _MyAppState extends State<MyApp> {
.ephemeralAsWebAuthenticationSession),
),
),
if (Platform.isIOS)
if (!kIsWeb && Platform.isIOS)
Padding(
padding: const EdgeInsets.all(8.0),
child: ElevatedButton(
Expand All @@ -139,7 +177,7 @@ class _MyAppState extends State<MyApp> {
: null,
child: const Text('End session'),
),
if (Platform.isIOS || Platform.isMacOS)
if (!kIsWeb && (Platform.isIOS || Platform.isMacOS))
Padding(
padding: const EdgeInsets.all(8.0),
child: ElevatedButton(
Expand All @@ -153,7 +191,7 @@ class _MyAppState extends State<MyApp> {
child:
const Text('End session using ephemeral session'),
)),
if (Platform.isIOS)
if (!kIsWeb && Platform.isIOS)
Padding(
padding: const EdgeInsets.all(8.0),
child: ElevatedButton(
Expand Down
19 changes: 19 additions & 0 deletions flutter_appauth/example/web/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<!DOCTYPE html>
<html lang="en">
<head>
<base href="/">

<meta charset="UTF-8">
<meta content="IE=Edge" http-equiv="X-UA-Compatible">
<meta name="description" content="A new Flutter project.">

<meta name="apple-mobile-web-app-capable" content="yes">
<meta name="apple-mobile-web-app-status-bar-style" content="black">
<meta name="apple-mobile-web-app-title" content="flutter_appauth_example">

<title>flutter_appauth_example</title>
</head>
<body>
<script src="main.dart.js" type="application/javascript"></script>
</body>
</html>
11 changes: 11 additions & 0 deletions flutter_appauth/example/web/manifest.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"name": "flutter_appauth_example",
"short_name": "flutter_appauth_example",
"start_url": ".",
"display": "standalone",
"background_color": "#0175C2",
"theme_color": "#0175C2",
"description": "A Flutter AppAuth example application.",
"orientation": "portrait-primary",
"prefer_related_applications": false
}
Loading