Add a POC OAuth client implementation

I've registered GitJournal as an app on Github and tried to get the
access_token within the app. This seems to work. Though, I need to
provide the client secret as well. It's quite sad that GitHub does not
even support the Implicit Grant auth type.

Credit: https://stackoverflow.com/questions/46196240/oauth2-flow-in-flutter-app
This commit is contained in:
Vishesh Handa
2019-01-23 20:17:59 +01:00
parent 03db7d62e7
commit c2e49bb630
4 changed files with 101 additions and 1 deletions

51
lib/oauthapp.dart Normal file
View File

@ -0,0 +1,51 @@
import 'package:flutter/material.dart';
import 'package:journal/apis/git.dart';
import 'package:flutter/services.dart';
import 'package:url_launcher/url_launcher.dart';
const _platform = const MethodChannel('gitjournal.io/git');
// Actual message handler:
Future _handleMessages(MethodCall call) async {
switch (call.method) {
case "onURL":
print("Call onURL" + call.arguments.toString());
// Do something nice using call.arguments["URL"]
}
}
class OAuthApp extends StatefulWidget {
@override
OAuthAppState createState() {
return new OAuthAppState();
}
}
class OAuthAppState extends State<OAuthApp> {
void initState() {
super.initState();
_platform.setMethodCallHandler(_handleMessages);
}
@override
Widget build(BuildContext context) {
return new MaterialApp(
title: 'OAuth App',
home: Scaffold(
appBar: AppBar(
title: Text('OAuth Test'),
),
body: Column(children: <Widget>[
RaisedButton(
child: Text("Open OAuth URL"),
onPressed: () {
var url =
"https://github.com/login/oauth/authorize?client_id=aa3072cbfb02b1db14ed&scope=repo";
launch(url);
},
),
]),
),
);
}
}