1
0
mirror of https://github.com/git-touch/git-touch synced 2025-02-02 17:07:06 +01:00

feat(github): add public repos only login option

closes #133
This commit is contained in:
Rongjian Zhang 2021-01-30 16:18:31 +08:00
parent c1b3d330e0
commit 31c43eebc8
2 changed files with 10 additions and 2 deletions

View File

@ -728,9 +728,11 @@ class AuthModel with ChangeNotifier {
} }
String _oauthState; String _oauthState;
void redirectToGithubOauth() { void redirectToGithubOauth([publicOnly = false]) {
_oauthState = nanoid(); _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( launchUrl(
'https://github.com/login/oauth/authorize?client_id=$clientId&redirect_uri=gittouch://login&scope=$scope&state=$_oauthState', 'https://github.com/login/oauth/authorize?client_id=$clientId&redirect_uri=gittouch://login&scope=$scope&state=$_oauthState',
); );

View File

@ -157,6 +157,12 @@ class _LoginScreenState extends State<LoginScreen> {
auth.redirectToGithubOauth(); auth.redirectToGithubOauth();
}, },
), ),
ActionItem(
text: 'via OAuth (Public repos only)',
onTap: (_) {
auth.redirectToGithubOauth(true);
},
),
ActionItem( ActionItem(
text: 'via Personal token', text: 'via Personal token',
onTap: (_) async { onTap: (_) async {