authenticateUser method
Future<String?>
authenticateUser(
- AuthInfo authInfo,
- String scope,
- String deviceCodeUrl,
- BuildContext context,
Implementation
Future<String?> authenticateUser(AuthInfo authInfo, String scope,
String deviceCodeUrl, BuildContext context) async {
try {
final deviceCodeResponse =
await getDeviceCode(authInfo.clientId, scope, deviceCodeUrl);
final userCode = deviceCodeResponse['user_code'];
final verificationUri = deviceCodeResponse['verification_uri'];
String fullVerificationUrl = "$verificationUri?code=$userCode";
print('Please go to $fullVerificationUrl');
showDialog<void>(
context: context,
builder: (BuildContext context) {
return AlertDialog(
title: const Text('Login with your phone'),
content: SizedBox(
height: 200,
width: 200,
child: QrImageView(
eyeStyle: const QrEyeStyle(
color: Colors.white,
eyeShape: QrEyeShape.square,
),
dataModuleStyle: const QrDataModuleStyle(
color: Colors.white,
dataModuleShape: QrDataModuleShape.square,
),
data: fullVerificationUrl,
version: QrVersions.auto,
// size: 200.0,
),
),
actions: <Widget>[
TextButton(
style: TextButton.styleFrom(
textStyle: Theme.of(context).textTheme.labelLarge,
),
child: const Text('Done'),
onPressed: () {
Navigator.of(context).pop();
},
),
],
);
},
);
final code = deviceCodeResponse['device_code'];
final interval = deviceCodeResponse['interval'];
var token = await pollForToken(
code,
interval,
authInfo.clientId,
authInfo.tokenUrl,
scope,
);
return token;
} catch (e) {
print('Error: $e');
}
return null;
}