oidc buttons, depends on server options
Signed-off-by: fufesou <shuanglongchen@yeah.net>
This commit is contained in:
parent
eab67949eb
commit
5a88841ffd
@ -4,6 +4,7 @@ import 'dart:convert';
|
|||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:flutter_hbb/common/hbbs/hbbs.dart';
|
import 'package:flutter_hbb/common/hbbs/hbbs.dart';
|
||||||
import 'package:flutter_hbb/models/platform_model.dart';
|
import 'package:flutter_hbb/models/platform_model.dart';
|
||||||
|
import 'package:flutter_hbb/models/user_model.dart';
|
||||||
import 'package:get/get.dart';
|
import 'package:get/get.dart';
|
||||||
import 'package:flutter_svg/flutter_svg.dart';
|
import 'package:flutter_svg/flutter_svg.dart';
|
||||||
import 'package:url_launcher/url_launcher.dart';
|
import 'package:url_launcher/url_launcher.dart';
|
||||||
@ -362,6 +363,8 @@ class LoginWidgetUserPass extends StatelessWidget {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const kAuthReqTypeOidc = 'oidc/';
|
||||||
|
|
||||||
/// common login dialog for desktop
|
/// common login dialog for desktop
|
||||||
/// call this directly
|
/// call this directly
|
||||||
Future<bool?> loginDialog() async {
|
Future<bool?> loginDialog() async {
|
||||||
@ -375,6 +378,8 @@ Future<bool?> loginDialog() async {
|
|||||||
var isInProgress = false;
|
var isInProgress = false;
|
||||||
final RxString curOP = ''.obs;
|
final RxString curOP = ''.obs;
|
||||||
|
|
||||||
|
final loginOptions = await UserModel.queryLoginOptions();
|
||||||
|
|
||||||
final res = await gFFI.dialogManager.show<bool>((setState, close, context) {
|
final res = await gFFI.dialogManager.show<bool>((setState, close, context) {
|
||||||
username.addListener(() {
|
username.addListener(() {
|
||||||
if (usernameMsg != null) {
|
if (usernameMsg != null) {
|
||||||
@ -446,6 +451,42 @@ Future<bool?> loginDialog() async {
|
|||||||
setState(() => isInProgress = false);
|
setState(() => isInProgress = false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
final oidcOptions = loginOptions
|
||||||
|
.where((opt) => opt.startsWith(kAuthReqTypeOidc))
|
||||||
|
.map((opt) => opt.substring(kAuthReqTypeOidc.length))
|
||||||
|
.toList();
|
||||||
|
|
||||||
|
thirdAuthWidget() => Offstage(
|
||||||
|
offstage: oidcOptions.isEmpty,
|
||||||
|
child: Column(
|
||||||
|
children: [
|
||||||
|
const SizedBox(
|
||||||
|
height: 8.0,
|
||||||
|
),
|
||||||
|
Center(
|
||||||
|
child: Text(
|
||||||
|
translate('or'),
|
||||||
|
style: TextStyle(fontSize: 16),
|
||||||
|
)),
|
||||||
|
const SizedBox(
|
||||||
|
height: 8.0,
|
||||||
|
),
|
||||||
|
LoginWidgetOP(
|
||||||
|
ops: [
|
||||||
|
ConfigOP(op: 'GitHub', iconWidth: 20),
|
||||||
|
ConfigOP(op: 'Google', iconWidth: 20),
|
||||||
|
ConfigOP(op: 'Okta', iconWidth: 38),
|
||||||
|
].where((op) => oidcOptions.contains(op.op.toLowerCase())).toList(),
|
||||||
|
curOP: curOP,
|
||||||
|
cbLogin: (String username) {
|
||||||
|
gFFI.userModel.userName.value = username;
|
||||||
|
close(true);
|
||||||
|
},
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
);
|
||||||
|
|
||||||
return CustomAlertDialog(
|
return CustomAlertDialog(
|
||||||
title: Text(translate('Login')),
|
title: Text(translate('Login')),
|
||||||
contentBoxConstraints: BoxConstraints(minWidth: 400),
|
contentBoxConstraints: BoxConstraints(minWidth: 400),
|
||||||
@ -465,29 +506,7 @@ Future<bool?> loginDialog() async {
|
|||||||
onLogin: onLogin,
|
onLogin: onLogin,
|
||||||
userFocusNode: userFocusNode,
|
userFocusNode: userFocusNode,
|
||||||
),
|
),
|
||||||
const SizedBox(
|
thirdAuthWidget(),
|
||||||
height: 8.0,
|
|
||||||
),
|
|
||||||
Center(
|
|
||||||
child: Text(
|
|
||||||
translate('or'),
|
|
||||||
style: TextStyle(fontSize: 16),
|
|
||||||
)),
|
|
||||||
const SizedBox(
|
|
||||||
height: 8.0,
|
|
||||||
),
|
|
||||||
LoginWidgetOP(
|
|
||||||
ops: [
|
|
||||||
ConfigOP(op: 'GitHub', iconWidth: 20),
|
|
||||||
ConfigOP(op: 'Google', iconWidth: 20),
|
|
||||||
ConfigOP(op: 'Okta', iconWidth: 38),
|
|
||||||
],
|
|
||||||
curOP: curOP,
|
|
||||||
cbLogin: (String username) {
|
|
||||||
gFFI.userModel.userName.value = username;
|
|
||||||
close(true);
|
|
||||||
},
|
|
||||||
),
|
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
actions: [dialogButton('Close', onPressed: onDialogCancel)],
|
actions: [dialogButton('Close', onPressed: onDialogCancel)],
|
||||||
|
@ -109,7 +109,7 @@ class UserModel {
|
|||||||
try {
|
try {
|
||||||
body = jsonDecode(resp.body);
|
body = jsonDecode(resp.body);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
print("jsonDecode resp body failed: ${e.toString()}");
|
print("login: jsonDecode resp body failed: ${e.toString()}");
|
||||||
rethrow;
|
rethrow;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -121,7 +121,7 @@ class UserModel {
|
|||||||
try {
|
try {
|
||||||
loginResponse = LoginResponse.fromJson(body);
|
loginResponse = LoginResponse.fromJson(body);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
print("jsonDecode LoginResponse failed: ${e.toString()}");
|
print("login: jsonDecode LoginResponse failed: ${e.toString()}");
|
||||||
rethrow;
|
rethrow;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -131,4 +131,15 @@ class UserModel {
|
|||||||
|
|
||||||
return loginResponse;
|
return loginResponse;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static Future<List<dynamic>> queryLoginOptions() async {
|
||||||
|
final url = await bind.mainGetApiServer();
|
||||||
|
final resp = await http.get(Uri.parse('$url/api/login-options'));
|
||||||
|
try {
|
||||||
|
return jsonDecode(resp.body);
|
||||||
|
} catch (e) {
|
||||||
|
print("queryLoginOptions: jsonDecode resp body failed: ${e.toString()}");
|
||||||
|
return [];
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user