identity_server 0.0.3 identity_server: ^0.0.3 copied to clipboard
plugin for authenticate with auth 2
import 'package:identity_server/add-oauth.dart';
import 'package:identity_server/model/config.dart';
import 'package:flutter/material.dart';
void main() => runApp(new MyApp());
class MyApp extends StatefulWidget {
@override
_MyAppState createState() => new _MyAppState();
}
class _MyAppState extends State<MyApp> {
@override
initState() {
super.initState();
}
@override
Widget build(BuildContext context) {
return new MaterialApp(debugShowCheckedModeBanner: false,
title: 'AAD OAuth Demo',
theme: new ThemeData(
primarySwatch: Colors.blue,
),
home: new MyHomePage(title: 'AAD OAuth Home'),
);
}
}
class MyHomePage extends StatefulWidget {
MyHomePage({Key key, this.title}) : super(key: key);
final String title;
@override
_MyHomePageState createState() => new _MyHomePageState();
}
class _MyHomePageState extends State<MyHomePage> {
static String clientId = 'ZPonto';
static String scopes = 'openid profile offline_access';
static String redirectUrl = 'net.openid.appzponto:/oauth2redirect';
static final Config config = new Config(clientId,scopes, redirectUrl);
final AadOAuth oauth = AadOAuth(config);
Widget build(BuildContext context) {
// adjust window size for browser login
var screenSize = MediaQuery.of(context).size;
var rectSize = Rect.fromLTWH(0.0, 25.0, screenSize.width, screenSize.height - 25);
oauth.setWebViewScreenSize(rectSize);
return new Scaffold(
appBar: new AppBar(
title: new Text(widget.title),
),
body: ListView(
children: <Widget>[
ListTile(
title: Text(
"AzureAD OAuth",
style: Theme.of(context).textTheme.headline,
),
),
ListTile(
leading: Icon(Icons.launch),
title: Text('Login'),
onTap: () {
login();
},
),
ListTile(
leading: Icon(Icons.security),
title: Text('Authorize'),
onTap: () {
},
),
ListTile(
leading: Icon(Icons.delete),
title: Text('Logout'),
onTap: () {
logout();
},
),
],
),
);
}
void showError(dynamic ex) {
showMessage(ex.toString());
}
void showMessage(String text) {
var alert = new AlertDialog(content: new Text(text), actions: <Widget>[
new FlatButton(
child: const Text("Ok"),
onPressed: () {
Navigator.pop(context);
})
]);
showDialog(context: context, builder: (BuildContext context) => alert);
}
void login() async {
try {
await oauth.login();
String accessToken = await oauth.getAccessToken();
showMessage("Logged in successfully, your access token: $accessToken");
} catch (e) {
showError(e);
}
}
void logout() async {
await oauth.logout();
showMessage("Logged out");
}
}