startAuthFlow method
Implementation
Future<void> startAuthFlow() async {
List<String> scopes = [];
if (widget._controller.initialScopes != null) {
scopes.addAll(widget._controller.initialScopes!);
}
if (widget._controller.onInitiated != null) {
ScreenController()
.executeAction(context, widget._controller.onInitiated!);
}
OAuthServiceToken? token;
try {
// Server doesn't always need to return a token if they don't want to,
// but we have code to create an empty token as needed.
// So null token here means some error occurs along the way
token =
await OAuthControllerImpl().authorize(context, OAuthService.google,
scope: ConnectUtils.getScopesAsString(scopes),
forceNewTokens: true, // this always force the flow again
tokenExchangeAPI: widget._controller.tokenExchangeAPI);
// dispatch success
if (token != null && widget._controller.onAuthorized != null) {
ScreenController()
.executeAction(context, widget._controller.onAuthorized!);
return;
}
} catch (e) {
if (e is PlatformException && e.code == 'CANCELED') {
if (widget._controller.onCanceled != null) {
ScreenController()
.executeAction(context, widget._controller.onCanceled!);
}
return;
}
}
// dispatch error
if (widget._controller.onError != null && token == null) {
ScreenController().executeAction(context, widget._controller.onError!);
}
}