Commit 5b6b1663 authored by Koen van der Veen's avatar Koen van der Veen
Browse files

make open window methods async for safari

parent 1de0e0aa
Pipeline #10379 passed with stages
in 4 minutes and 12 seconds
Showing with 38 additions and 10 deletions
+38 -10
......@@ -26,6 +26,8 @@ class OAuthProvider with ChangeNotifier {
final GraphService _graphService;
final GitlabService _gitlabService;
String? gitlabOauthUrl;
OAuthProvider(
this._prefs,
this._podService,
......@@ -132,13 +134,16 @@ class OAuthProvider with ChangeNotifier {
_podService.createItem(item: item);
}
Future<void> openOAuthWindow() async {
setGitlabOauthUrl() async {
List<String> scopes = ['api', 'read_repository', 'write_repository'];
String url = await _podService.oauth2url(
gitlabOauthUrl = await _podService.oauth2url(
_gitlabService.redirectUrl, scopes, 'gitlab');
}
html.window.open(url, '_blank', 'location=yes, height=800,width=600');
openOAuthWindow() {
// safari only allows popup when a synchronous function is directly called on button click. Dont complicate this function
html.window
.open(gitlabOauthUrl!, '_blank', 'location=yes, height=800,width=600');
}
Future<Map<String, dynamic>> _requestOauthAccessToken(String oauthVerifier,
......@@ -169,6 +174,7 @@ class OAuthProvider with ChangeNotifier {
}
Future<void> initGitlabOAuth() async {
setGitlabOauthUrl();
await setGitlabAccesTokenFromPod();
if (_gitlabService.gitlabAccessToken == null) {
// start a listener for accessToken, if it finds one, set in the gitlab api and test auth
......@@ -212,16 +218,25 @@ class OAuthProvider with ChangeNotifier {
}
/// Twitter
///
Future<void> initTwitterOAuth(BuildContext context) async {
String? twitterOauthToken;
String? twitterOauthTokenSecret;
setTwitterOauthToken() async {
String redirectUrl = '${_gitlabService.endpoint}/oauth?state=twitter';
var res = await _oAuthService.oauthRequestToken('twitter', redirectUrl);
twitterOauthToken = res['oauth_token'];
twitterOauthTokenSecret = res['oauth_token_secret'];
}
void initTwitterOAuth(BuildContext context) {
_setOAuthCompleted(false);
var res = await _oAuthService.oauthRequestToken('twitter', redirectUrl);
final queryParameters = {'oauth_token': res['oauth_token']};
final queryParameters = {'oauth_token': twitterOauthToken!};
// we are using this in the redirect screen
_prefs.setString('oauthTokenSecret', res['oauth_token_secret']);
_prefs.setString('oauthTokenSecret', twitterOauthTokenSecret!);
var url = Uri.https('api.twitter.com', '/oauth/authorize', queryParameters);
......
......@@ -5,12 +5,24 @@ import 'package:memri/utilities/helpers/responsive_helper.dart';
import 'package:memri/widgets/screen_error.dart';
import 'package:provider/provider.dart';
class ImporterConnectTwitter extends StatelessWidget {
class ImporterConnectTwitter extends StatefulWidget {
const ImporterConnectTwitter({Key? key, required this.parentContext})
: super(key: key);
final BuildContext parentContext;
@override
State<ImporterConnectTwitter> createState() => _ImporterConnectTwitterState();
}
class _ImporterConnectTwitterState extends State<ImporterConnectTwitter> {
@override
initState() {
var provider = Provider.of<OAuthProvider>(context, listen: false);
provider.setTwitterOauthToken();
super.initState();
}
@override
Widget build(BuildContext context) {
return Consumer<OAuthProvider>(builder: (context, provider, _) {
......@@ -38,7 +50,8 @@ class ImporterConnectTwitter extends StatelessWidget {
),
SizedBox(height: 30),
TextButton(
onPressed: () => provider.initTwitterOAuth(parentContext),
onPressed: () =>
provider.initTwitterOAuth(widget.parentContext),
child:
Text('Authorise Twitter', style: AppStyles.buttonLabel),
style: tertiaryButtonStyle),
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment