This repository was archived by the owner on Jun 10, 2026. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 30
Expand file tree
/
Copy pathbutton_refresh_token.dart
More file actions
122 lines (116 loc) · 3.93 KB
/
button_refresh_token.dart
File metadata and controls
122 lines (116 loc) · 3.93 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
import 'package:aad_b2c_webview/aad_b2c_webview.dart';
import 'package:example/main.dart';
import 'package:example/widgets/button_widget.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
class ButtonRefreshToken extends StatefulWidget {
const ButtonRefreshToken({super.key});
@override
State<ButtonRefreshToken> createState() => _ButtonRefreshTokenState();
}
class _ButtonRefreshTokenState extends State<ButtonRefreshToken>
with MixinControllerAccess {
final _formKey = GlobalKey<FormState>();
bool _isLoading = false;
bool _enableToCopy = false;
AzureTokenResponseEntity? response;
final _refreshTokenController = TextEditingController();
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(),
body: Form(
key: _formKey,
child: Padding(
padding: const EdgeInsets.all(16.0),
child: Column(
crossAxisAlignment: CrossAxisAlignment.center,
children: [
const Text(
'Refresh Token Page',
style: TextStyle(
fontSize: 24.0,
fontWeight: FontWeight.bold,
),
),
const SizedBox(height: 32.0),
TextFormField(
controller: _refreshTokenController,
enabled: !_isLoading,
maxLines: 10,
autofocus: true,
decoration: const InputDecoration(
labelText: 'Old Refresh Token',
),
validator: (value) {
if (value == null || value.isEmpty) {
return 'Please, put the old refresh token';
}
return null;
},
),
const SizedBox(height: 16.0),
if (_isLoading)
const CircularProgressIndicator()
else
ButtonWidget(
onTap: _refreshToken,
title: 'Refresh token',
icon: Icons.refresh_outlined,
backgroundColor: Colors.deepOrangeAccent,
),
const SizedBox(height: 16.0),
ButtonWidget(
onTap: () {
if (_enableToCopy) {
Clipboard.setData(
ClipboardData(
text: 'access:${response?.accessToken}\n\n'
'idToken:${response?.idToken}\n\n'
'refreshToken:${response?.refreshToken}',
),
);
}
},
title: 'Copy Refresh Token',
icon: Icons.copy_all,
backgroundColor: _enableToCopy
? Colors.orange
: Colors.deepOrangeAccent.shade100,
),
const SizedBox(height: 16.0),
],
),
),
),
);
}
void _refreshToken() async {
if (_formKey.currentState?.validate() ?? false) {
setState(() => _isLoading = true);
response = await controller.refreshToken(
B2CAuthEntity(
refreshToken: _refreshTokenController.text.trim(),
userFlowName: aadB2CUserFlowName,
tenantBaseUrl: aadB2CUserAuthFlow,
clientId: aadB2CClientID,
),
);
setState(() => _isLoading = false);
if (response != null) {
setState(() => _enableToCopy = true);
var snackBar = const SnackBar(
content: Text('Successfully Refresh token!'),
backgroundColor: Colors.green,
);
ScaffoldMessenger.of(context).showSnackBar(snackBar);
} else {
var snackBar = const SnackBar(
content: Text('Error in refresh token'),
backgroundColor: Colors.redAccent,
);
ScaffoldMessenger.of(context).showSnackBar(snackBar);
}
}
}
}