From 31c43eebc8e3b11a60da92926b94b4c052029e9a Mon Sep 17 00:00:00 2001 From: Rongjian Zhang Date: Sat, 30 Jan 2021 16:18:31 +0800 Subject: [PATCH] feat(github): add public repos only login option closes #133 --- lib/models/auth.dart | 6 ++++-- lib/screens/login.dart | 6 ++++++ 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/lib/models/auth.dart b/lib/models/auth.dart index a0c3aff..4bd751f 100644 --- a/lib/models/auth.dart +++ b/lib/models/auth.dart @@ -728,9 +728,11 @@ class AuthModel with ChangeNotifier { } String _oauthState; - void redirectToGithubOauth() { + void redirectToGithubOauth([publicOnly = false]) { _oauthState = nanoid(); - var scope = Uri.encodeComponent('user,repo,read:org,notifications'); + final repoScope = publicOnly ? 'public_repo' : 'repo'; + final scope = Uri.encodeComponent( + ['user', repoScope, 'read:org', 'notifications'].join(',')); launchUrl( 'https://github.com/login/oauth/authorize?client_id=$clientId&redirect_uri=gittouch://login&scope=$scope&state=$_oauthState', ); diff --git a/lib/screens/login.dart b/lib/screens/login.dart index 8d3ed93..d324266 100644 --- a/lib/screens/login.dart +++ b/lib/screens/login.dart @@ -157,6 +157,12 @@ class _LoginScreenState extends State { auth.redirectToGithubOauth(); }, ), + ActionItem( + text: 'via OAuth (Public repos only)', + onTap: (_) { + auth.redirectToGithubOauth(true); + }, + ), ActionItem( text: 'via Personal token', onTap: (_) async {