flutter - Github Flutter 登录
问题描述
Github API指定需要重定向 url 才能获得授权的登录结果。但是,如果我正在开发一个不使用 webviews 的非混合颤振应用程序。在提示用户使用URL Launcher之类的登录后,我将如何重定向用户以返回应用程序?
解决方案
您可以使用包https://pub.dev/packages/simple_auth
代码片段
final simpleAuth.GithubApi githubApi = new simpleAuth.GithubApi(
"github", "clientId", "clientSecret", "redirect:/",
scopes: [
"user",
"repo",
"public_repo",
]);
void login(simpleAuth.AuthenticatedApi api) async {
try {
var success = await api.authenticate();
showMessage("Logged in success: $success");
} catch (e) {
showError(e);
}
}
...
ListTile(
leading: Icon(Icons.launch),
title: Text('Login'),
onTap: () {
login(githubApi);
},
),
ListTile(
leading: Icon(Icons.delete),
title: Text('Logout'),
onTap: () {
logout(githubApi);
},
),
完整示例代码 https://github.com/Clancey/simple_auth/blob/master/simple_auth_flutter_example/lib/main.dart
推荐阅读
- arrays - 如何在keil uVision中定义一个二进制数数组?
- gdal - GeoTIFF 转换
- express - 快速会话 - 管理员可以删除其他用户会话吗?
- azure - 无法从门户创建存储帐户:名称已被占用
- django - 如何在 django 平台中为嵌套评论系统创建视图?
- java - 错误:JavaFX 运行时组件丢失,并且是运行此应用程序所必需的。使用 gradle 运行项目
- java - 如何将多个整数从 Bash shell 脚本传递到 Java System.in?
- sql - proc sql中Group By类中的Case语句和聚合
- javascript - 将一个 useReducer 状态传递给另一个 useReducer
- python - 如何检查存储在列表中的字典中的键