forked from baron/baron-sso
userfront 연동이력 맞춤
This commit is contained in:
11
userfront/lib/core/constants/error_whitelist.dart
Normal file
11
userfront/lib/core/constants/error_whitelist.dart
Normal file
@@ -0,0 +1,11 @@
|
||||
const Map<String, String> errorWhitelistMessages = {
|
||||
'settings_disabled': '현재 계정 설정 화면은 준비 중입니다.',
|
||||
'invalid_session': '세션이 만료되었습니다. 다시 로그인해 주세요.',
|
||||
'verification_required': '추가 인증이 필요합니다. 안내에 따라 진행해 주세요.',
|
||||
'recovery_expired': '재설정 링크가 만료되었습니다. 다시 요청해 주세요.',
|
||||
'recovery_invalid': '재설정 링크가 유효하지 않습니다.',
|
||||
'consent_required': '앱 접근 동의가 필요합니다.',
|
||||
'rate_limited': '요청이 많습니다. 잠시 후 다시 시도해 주세요.',
|
||||
'not_found': '요청한 페이지를 찾을 수 없습니다.',
|
||||
'bad_request': '입력값을 확인해 주세요.',
|
||||
};
|
||||
@@ -2,7 +2,7 @@ import 'dart:convert';
|
||||
import 'package:http/http.dart' as http;
|
||||
import 'package:flutter_dotenv/flutter_dotenv.dart';
|
||||
import 'http_client.dart';
|
||||
import 'dart:html' as html;
|
||||
import 'web_window.dart';
|
||||
|
||||
class AuthProxyService {
|
||||
static String _envOrDefault(String key, String fallback) {
|
||||
@@ -215,7 +215,7 @@ class AuthProxyService {
|
||||
if (response.statusCode == 200) {
|
||||
final data = jsonDecode(response.body);
|
||||
if (data['redirectTo'] != null && data['redirectTo'].isNotEmpty) {
|
||||
html.window.location.href = data['redirectTo'];
|
||||
webWindow.redirectTo(data['redirectTo']);
|
||||
}
|
||||
return data;
|
||||
} else {
|
||||
@@ -254,6 +254,36 @@ class AuthProxyService {
|
||||
}
|
||||
}
|
||||
|
||||
static Future<Map<String, dynamic>> acceptOidcLogin(
|
||||
String loginChallenge, {
|
||||
String? token,
|
||||
}) async {
|
||||
final url = Uri.parse('$_baseUrl/api/v1/auth/oidc/login/accept');
|
||||
final headers = <String, String>{
|
||||
'Content-Type': 'application/json',
|
||||
};
|
||||
if (token != null && token.isNotEmpty) {
|
||||
headers['Authorization'] = 'Bearer $token';
|
||||
}
|
||||
final client = createHttpClient(withCredentials: true);
|
||||
try {
|
||||
final response = await client.post(
|
||||
url,
|
||||
headers: headers,
|
||||
body: jsonEncode({'login_challenge': loginChallenge}),
|
||||
);
|
||||
|
||||
if (response.statusCode == 200) {
|
||||
return jsonDecode(response.body);
|
||||
} else {
|
||||
final errorBody = jsonDecode(response.body);
|
||||
throw Exception(errorBody['error'] ?? 'Failed to accept OIDC login');
|
||||
}
|
||||
} finally {
|
||||
client.close();
|
||||
}
|
||||
}
|
||||
|
||||
static Future<Map<String, dynamic>> initiatePasswordReset(String loginId, {bool? drySend}) async {
|
||||
final url = Uri.parse('$_baseUrl/api/v1/auth/password/reset/initiate');
|
||||
final response = await http.post(
|
||||
|
||||
1
userfront/lib/core/services/web_window.dart
Normal file
1
userfront/lib/core/services/web_window.dart
Normal file
@@ -0,0 +1 @@
|
||||
export 'web_window_stub.dart' if (dart.library.html) 'web_window_web.dart';
|
||||
17
userfront/lib/core/services/web_window_stub.dart
Normal file
17
userfront/lib/core/services/web_window_stub.dart
Normal file
@@ -0,0 +1,17 @@
|
||||
class WebWindow {
|
||||
void redirectTo(String url) {}
|
||||
|
||||
void alert(String message) {}
|
||||
|
||||
void close() {}
|
||||
|
||||
bool hasOpener() {
|
||||
return false;
|
||||
}
|
||||
|
||||
bool redirectOpenerTo(String url) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
final webWindow = WebWindow();
|
||||
34
userfront/lib/core/services/web_window_web.dart
Normal file
34
userfront/lib/core/services/web_window_web.dart
Normal file
@@ -0,0 +1,34 @@
|
||||
import 'dart:html' as html;
|
||||
|
||||
class WebWindow {
|
||||
void redirectTo(String url) {
|
||||
html.window.location.href = url;
|
||||
}
|
||||
|
||||
void alert(String message) {
|
||||
html.window.alert(message);
|
||||
}
|
||||
|
||||
void close() {
|
||||
html.window.close();
|
||||
}
|
||||
|
||||
bool hasOpener() {
|
||||
return html.window.opener != null;
|
||||
}
|
||||
|
||||
bool redirectOpenerTo(String url) {
|
||||
final opener = html.window.opener;
|
||||
if (opener == null) {
|
||||
return false;
|
||||
}
|
||||
try {
|
||||
opener.location.href = url;
|
||||
return true;
|
||||
} catch (_) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
final webWindow = WebWindow();
|
||||
@@ -1,7 +1,6 @@
|
||||
import 'dart:html' as html;
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:userfront/core/services/auth_proxy_service.dart';
|
||||
import 'package:userfront/core/services/web_window.dart';
|
||||
|
||||
class ConsentScreen extends StatefulWidget {
|
||||
final String consentChallenge;
|
||||
@@ -13,8 +12,15 @@ class ConsentScreen extends StatefulWidget {
|
||||
}
|
||||
|
||||
class _ConsentScreenState extends State<ConsentScreen> {
|
||||
static const _ink = Color(0xFF1A1F2C);
|
||||
static const _surface = Colors.white;
|
||||
static const _border = Color(0xFFE5E7EB);
|
||||
static const _subtle = Color(0xFFF7F8FA);
|
||||
static const _accent = Color(0xFF2563EB);
|
||||
|
||||
Map<String, dynamic>? _consentInfo;
|
||||
bool _isLoading = true;
|
||||
bool _isSubmitting = false;
|
||||
String? _error;
|
||||
|
||||
@override
|
||||
@@ -32,7 +38,7 @@ class _ConsentScreenState extends State<ConsentScreen> {
|
||||
});
|
||||
} catch (e) {
|
||||
setState(() {
|
||||
_error = 'Failed to load consent information: $e';
|
||||
_error = '권한 정보를 불러오지 못했습니다: $e';
|
||||
_isLoading = false;
|
||||
});
|
||||
}
|
||||
@@ -40,83 +46,498 @@ class _ConsentScreenState extends State<ConsentScreen> {
|
||||
|
||||
Future<void> _acceptConsent() async {
|
||||
setState(() {
|
||||
_isLoading = true;
|
||||
_isSubmitting = true;
|
||||
_error = null;
|
||||
});
|
||||
try {
|
||||
final result =
|
||||
await AuthProxyService.acceptConsent(widget.consentChallenge);
|
||||
if (result['redirectTo'] != null) {
|
||||
html.window.location.href = result['redirectTo'];
|
||||
} else {
|
||||
setState(() {
|
||||
_error = 'Consent accepted, but no redirect URL received.';
|
||||
_isLoading = false;
|
||||
});
|
||||
final redirectTo = result['redirectTo']?.toString() ?? '';
|
||||
if (redirectTo.isNotEmpty) {
|
||||
if (webWindow.hasOpener() && webWindow.redirectOpenerTo(redirectTo)) {
|
||||
// 팝업에서 호출된 경우, 부모 창으로 리다이렉트 후 현재 창을 닫습니다.
|
||||
webWindow.close();
|
||||
return;
|
||||
}
|
||||
webWindow.redirectTo(redirectTo);
|
||||
return;
|
||||
}
|
||||
setState(() {
|
||||
_error = '동의는 완료됐지만 이동할 주소를 받지 못했습니다.';
|
||||
});
|
||||
} catch (e) {
|
||||
setState(() {
|
||||
_error = 'Failed to accept consent: $e';
|
||||
_isLoading = false;
|
||||
_error = '동의 처리 중 오류가 발생했습니다: $e';
|
||||
});
|
||||
} finally {
|
||||
if (mounted) {
|
||||
setState(() => _isSubmitting = false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void _rejectConsent() {
|
||||
webWindow.alert('동의를 취소했습니다. 창을 닫아 주세요.');
|
||||
}
|
||||
|
||||
Map<String, dynamic>? _client() {
|
||||
final info = _consentInfo;
|
||||
if (info == null) return null;
|
||||
final client = info['client'];
|
||||
if (client is Map<String, dynamic>) {
|
||||
return client;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
String _resolveClientName(Map<String, dynamic>? client) {
|
||||
final name = client?['client_name']?.toString().trim();
|
||||
if (name != null && name.isNotEmpty) {
|
||||
return name;
|
||||
}
|
||||
final id = client?['client_id']?.toString().trim();
|
||||
if (id != null && id.isNotEmpty) {
|
||||
return id;
|
||||
}
|
||||
return '알 수 없는 앱';
|
||||
}
|
||||
|
||||
String? _resolveClientId(Map<String, dynamic>? client) {
|
||||
final id = client?['client_id']?.toString().trim();
|
||||
if (id != null && id.isNotEmpty) {
|
||||
return id;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
String? _resolveClientLogo(Map<String, dynamic>? client) {
|
||||
final logo = client?['logo_uri']?.toString().trim();
|
||||
if (logo != null && logo.isNotEmpty) {
|
||||
return logo;
|
||||
}
|
||||
final metadata = client?['metadata'];
|
||||
if (metadata is Map<String, dynamic>) {
|
||||
final metaLogo = metadata['logo_url']?.toString().trim();
|
||||
if (metaLogo != null && metaLogo.isNotEmpty) {
|
||||
return metaLogo;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
List<String> _requestedScopes() {
|
||||
final scopes = _consentInfo?['requested_scope'];
|
||||
if (scopes is List) {
|
||||
return scopes.map((e) => e.toString()).toList();
|
||||
}
|
||||
return const [];
|
||||
}
|
||||
|
||||
String _scopeDescription(String scope) {
|
||||
switch (scope) {
|
||||
case 'openid':
|
||||
return '로그인 상태 확인을 위한 기본 식별자';
|
||||
case 'profile':
|
||||
return '이름, 사용자 식별자 등 기본 프로필 정보';
|
||||
case 'email':
|
||||
return '이메일 주소 정보';
|
||||
case 'phone':
|
||||
return '휴대폰 번호 정보';
|
||||
default:
|
||||
return '앱에서 요청한 추가 권한';
|
||||
}
|
||||
}
|
||||
|
||||
Widget _buildInfoChip(IconData icon, String label) {
|
||||
return Container(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 12, vertical: 8),
|
||||
decoration: BoxDecoration(
|
||||
color: _subtle,
|
||||
borderRadius: BorderRadius.circular(999),
|
||||
border: Border.all(color: _border),
|
||||
),
|
||||
child: Row(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
Icon(icon, size: 16, color: _ink),
|
||||
const SizedBox(width: 6),
|
||||
Text(
|
||||
label,
|
||||
style: const TextStyle(
|
||||
fontSize: 12,
|
||||
color: _ink,
|
||||
fontWeight: FontWeight.w600,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final theme = Theme.of(context);
|
||||
final client = _client();
|
||||
final clientName = _resolveClientName(client);
|
||||
final clientId = _resolveClientId(client);
|
||||
final logoUrl = _resolveClientLogo(client);
|
||||
final scopes = _requestedScopes();
|
||||
|
||||
return Scaffold(
|
||||
appBar: AppBar(title: const Text('Grant Access')),
|
||||
body: Center(
|
||||
child: _isLoading
|
||||
? const CircularProgressIndicator()
|
||||
: _error != null
|
||||
? Text(_error!, style: const TextStyle(color: Colors.red))
|
||||
: _consentInfo != null
|
||||
? Card(
|
||||
elevation: 4,
|
||||
margin: const EdgeInsets.all(16),
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.all(24.0),
|
||||
child: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
Text(
|
||||
'${_consentInfo!['client']?['client_name'] ?? 'An application'} wants to access your account',
|
||||
style: Theme.of(context).textTheme.headlineSmall,
|
||||
textAlign: TextAlign.center,
|
||||
backgroundColor: _subtle,
|
||||
body: SafeArea(
|
||||
child: Center(
|
||||
child: SingleChildScrollView(
|
||||
padding: const EdgeInsets.all(24),
|
||||
child: ConstrainedBox(
|
||||
constraints: const BoxConstraints(maxWidth: 560),
|
||||
child: Container(
|
||||
decoration: BoxDecoration(
|
||||
color: _surface,
|
||||
borderRadius: BorderRadius.circular(20),
|
||||
border: Border.all(color: _border),
|
||||
boxShadow: [
|
||||
BoxShadow(
|
||||
color: Colors.black.withOpacity(0.04),
|
||||
blurRadius: 18,
|
||||
offset: const Offset(0, 8),
|
||||
),
|
||||
],
|
||||
),
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.fromLTRB(28, 28, 28, 24),
|
||||
child: _isLoading
|
||||
? Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
const CircularProgressIndicator(),
|
||||
const SizedBox(height: 16),
|
||||
Text(
|
||||
'권한 정보를 불러오는 중입니다...',
|
||||
style: theme.textTheme.bodyMedium?.copyWith(
|
||||
color: Colors.grey[600],
|
||||
),
|
||||
const SizedBox(height: 24),
|
||||
const Text('This will allow the application to:'),
|
||||
const SizedBox(height: 16),
|
||||
if (_consentInfo!['requested_scope'] != null)
|
||||
...(_consentInfo!['requested_scope'] as List)
|
||||
.map((scope) => ListTile(
|
||||
leading: const Icon(Icons.check_circle_outline),
|
||||
title: Text(scope.toString()),
|
||||
))
|
||||
.toList(),
|
||||
const SizedBox(height: 24),
|
||||
Row(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
|
||||
children: [
|
||||
TextButton(
|
||||
onPressed: () {
|
||||
// TODO: Implement reject consent
|
||||
html.window.alert('Consent rejected. You can close this window.');
|
||||
},
|
||||
child: const Text('Deny'),
|
||||
),
|
||||
],
|
||||
)
|
||||
: _consentInfo == null
|
||||
? Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text(
|
||||
'요청 정보를 확인할 수 없습니다.',
|
||||
style: theme.textTheme.bodyMedium?.copyWith(
|
||||
color: Colors.grey[700],
|
||||
),
|
||||
ElevatedButton(
|
||||
onPressed: _acceptConsent,
|
||||
child: const Text('Allow'),
|
||||
),
|
||||
if (_error != null) ...[
|
||||
const SizedBox(height: 12),
|
||||
Text(
|
||||
_error!,
|
||||
style: theme.textTheme.bodySmall?.copyWith(
|
||||
color: const Color(0xFFB91C1C),
|
||||
),
|
||||
),
|
||||
],
|
||||
)
|
||||
],
|
||||
),
|
||||
),
|
||||
)
|
||||
: const Text('No consent information available.'),
|
||||
const SizedBox(height: 16),
|
||||
OutlinedButton(
|
||||
onPressed: _fetchConsentInfo,
|
||||
style: OutlinedButton.styleFrom(
|
||||
foregroundColor: _ink,
|
||||
side: const BorderSide(color: _border),
|
||||
padding: const EdgeInsets.symmetric(
|
||||
horizontal: 16,
|
||||
vertical: 10,
|
||||
),
|
||||
shape: RoundedRectangleBorder(
|
||||
borderRadius: BorderRadius.circular(10),
|
||||
),
|
||||
),
|
||||
child: const Text('다시 시도'),
|
||||
),
|
||||
],
|
||||
)
|
||||
: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Row(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Container(
|
||||
width: 56,
|
||||
height: 56,
|
||||
decoration: BoxDecoration(
|
||||
color: _subtle,
|
||||
borderRadius: BorderRadius.circular(16),
|
||||
border: Border.all(color: _border),
|
||||
),
|
||||
child: logoUrl == null
|
||||
? const Icon(
|
||||
Icons.lock_outline,
|
||||
color: _ink,
|
||||
)
|
||||
: ClipRRect(
|
||||
borderRadius:
|
||||
BorderRadius.circular(14),
|
||||
child: Image.network(
|
||||
logoUrl,
|
||||
fit: BoxFit.cover,
|
||||
errorBuilder: (
|
||||
context,
|
||||
error,
|
||||
stackTrace,
|
||||
) {
|
||||
return const Icon(
|
||||
Icons.lock_outline,
|
||||
color: _ink,
|
||||
);
|
||||
},
|
||||
),
|
||||
),
|
||||
),
|
||||
const SizedBox(width: 16),
|
||||
Expanded(
|
||||
child: Column(
|
||||
crossAxisAlignment:
|
||||
CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text(
|
||||
'앱 권한 요청',
|
||||
style: theme.textTheme.titleLarge
|
||||
?.copyWith(
|
||||
fontWeight: FontWeight.w700,
|
||||
color: _ink,
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 6),
|
||||
Text(
|
||||
clientName,
|
||||
style: theme.textTheme.titleMedium
|
||||
?.copyWith(
|
||||
fontWeight: FontWeight.w600,
|
||||
color: _ink,
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 8),
|
||||
Wrap(
|
||||
spacing: 8,
|
||||
runSpacing: 8,
|
||||
children: [
|
||||
if (clientId != null)
|
||||
_buildInfoChip(
|
||||
Icons.vpn_key_outlined,
|
||||
'Client ID: $clientId',
|
||||
),
|
||||
_buildInfoChip(
|
||||
Icons.security_outlined,
|
||||
'요청 권한 ${scopes.length}개',
|
||||
),
|
||||
],
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
Text(
|
||||
'이 앱이 아래 정보에 접근하려고 합니다. 계속 진행하려면 동의 여부를 선택해 주세요.',
|
||||
style: theme.textTheme.bodyMedium?.copyWith(
|
||||
color: Colors.grey[700],
|
||||
height: 1.5,
|
||||
),
|
||||
),
|
||||
if (_error != null) ...[
|
||||
const SizedBox(height: 16),
|
||||
Container(
|
||||
padding: const EdgeInsets.all(12),
|
||||
decoration: BoxDecoration(
|
||||
color: const Color(0xFFFEE2E2),
|
||||
borderRadius: BorderRadius.circular(12),
|
||||
border: Border.all(
|
||||
color: const Color(0xFFFCA5A5),
|
||||
),
|
||||
),
|
||||
child: Row(
|
||||
crossAxisAlignment:
|
||||
CrossAxisAlignment.start,
|
||||
children: [
|
||||
const Icon(
|
||||
Icons.error_outline,
|
||||
color: Color(0xFFB91C1C),
|
||||
size: 20,
|
||||
),
|
||||
const SizedBox(width: 8),
|
||||
Expanded(
|
||||
child: Text(
|
||||
_error!,
|
||||
style: theme.textTheme.bodySmall
|
||||
?.copyWith(
|
||||
color: const Color(0xFFB91C1C),
|
||||
height: 1.4,
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
],
|
||||
const SizedBox(height: 20),
|
||||
Text(
|
||||
'요청된 권한',
|
||||
style: theme.textTheme.titleSmall?.copyWith(
|
||||
fontWeight: FontWeight.w600,
|
||||
color: _ink,
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 12),
|
||||
if (scopes.isEmpty)
|
||||
Text(
|
||||
'요청된 권한 정보가 없습니다.',
|
||||
style: theme.textTheme.bodySmall?.copyWith(
|
||||
color: Colors.grey[600],
|
||||
),
|
||||
)
|
||||
else
|
||||
Column(
|
||||
children: scopes
|
||||
.map(
|
||||
(scope) => Container(
|
||||
margin: const EdgeInsets.only(
|
||||
bottom: 10,
|
||||
),
|
||||
padding: const EdgeInsets.all(12),
|
||||
decoration: BoxDecoration(
|
||||
color: _subtle,
|
||||
borderRadius:
|
||||
BorderRadius.circular(12),
|
||||
border:
|
||||
Border.all(color: _border),
|
||||
),
|
||||
child: Row(
|
||||
crossAxisAlignment:
|
||||
CrossAxisAlignment.start,
|
||||
children: [
|
||||
const Icon(
|
||||
Icons.check_circle_outline,
|
||||
color: _accent,
|
||||
size: 20,
|
||||
),
|
||||
const SizedBox(width: 10),
|
||||
Expanded(
|
||||
child: Column(
|
||||
crossAxisAlignment:
|
||||
CrossAxisAlignment
|
||||
.start,
|
||||
children: [
|
||||
Text(
|
||||
scope,
|
||||
style: theme.textTheme
|
||||
.bodyMedium
|
||||
?.copyWith(
|
||||
fontWeight:
|
||||
FontWeight.w600,
|
||||
color: _ink,
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 4),
|
||||
Text(
|
||||
_scopeDescription(
|
||||
scope),
|
||||
style: theme.textTheme
|
||||
.bodySmall
|
||||
?.copyWith(
|
||||
color:
|
||||
Colors.grey[600],
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
)
|
||||
.toList(),
|
||||
),
|
||||
const SizedBox(height: 12),
|
||||
Text(
|
||||
'동의 후 자동으로 서비스로 이동합니다.',
|
||||
style: theme.textTheme.bodySmall?.copyWith(
|
||||
color: Colors.grey[600],
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 20),
|
||||
Wrap(
|
||||
spacing: 12,
|
||||
runSpacing: 12,
|
||||
children: [
|
||||
OutlinedButton(
|
||||
onPressed: _isSubmitting
|
||||
? null
|
||||
: _rejectConsent,
|
||||
style: OutlinedButton.styleFrom(
|
||||
foregroundColor: _ink,
|
||||
padding: const EdgeInsets.symmetric(
|
||||
horizontal: 18,
|
||||
vertical: 12,
|
||||
),
|
||||
side: const BorderSide(
|
||||
color: _border,
|
||||
),
|
||||
shape: RoundedRectangleBorder(
|
||||
borderRadius:
|
||||
BorderRadius.circular(10),
|
||||
),
|
||||
),
|
||||
child: const Text('취소'),
|
||||
),
|
||||
FilledButton(
|
||||
onPressed: _isSubmitting
|
||||
? null
|
||||
: _acceptConsent,
|
||||
style: FilledButton.styleFrom(
|
||||
backgroundColor: _ink,
|
||||
foregroundColor: Colors.white,
|
||||
padding: const EdgeInsets.symmetric(
|
||||
horizontal: 18,
|
||||
vertical: 12,
|
||||
),
|
||||
shape: RoundedRectangleBorder(
|
||||
borderRadius:
|
||||
BorderRadius.circular(10),
|
||||
),
|
||||
),
|
||||
child: _isSubmitting
|
||||
? Row(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: const [
|
||||
SizedBox(
|
||||
width: 16,
|
||||
height: 16,
|
||||
child:
|
||||
CircularProgressIndicator(
|
||||
strokeWidth: 2,
|
||||
color: Colors.white,
|
||||
),
|
||||
),
|
||||
SizedBox(width: 8),
|
||||
Text('처리 중...'),
|
||||
],
|
||||
)
|
||||
: const Text('동의하고 계속하기'),
|
||||
),
|
||||
],
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
@@ -7,18 +7,20 @@ class ErrorScreen extends StatelessWidget {
|
||||
final String? errorId;
|
||||
final String? errorCode;
|
||||
final String? description;
|
||||
final bool? isProdOverride;
|
||||
|
||||
const ErrorScreen({
|
||||
super.key,
|
||||
this.errorId,
|
||||
this.errorCode,
|
||||
this.description,
|
||||
this.isProdOverride,
|
||||
});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final theme = Theme.of(context);
|
||||
final isProd = AuthProxyService.isProdEnv;
|
||||
final isProd = isProdOverride ?? AuthProxyService.isProdEnv;
|
||||
final normalizedCode = (errorCode ?? '').trim();
|
||||
final hasCode = normalizedCode.isNotEmpty;
|
||||
final whitelistMessage = errorWhitelistMessages[normalizedCode];
|
||||
|
||||
@@ -10,7 +10,7 @@ import '../../../core/services/auth_proxy_service.dart';
|
||||
import '../../../core/services/auth_token_store.dart';
|
||||
import '../../../core/notifiers/auth_notifier.dart';
|
||||
import '../../profile/domain/notifiers/profile_notifier.dart';
|
||||
import 'dart:html' as html;
|
||||
import '../../../core/services/web_window.dart';
|
||||
|
||||
class LoginScreen extends ConsumerStatefulWidget {
|
||||
final String? verificationToken;
|
||||
@@ -109,10 +109,7 @@ class _LoginScreenState extends ConsumerState<LoginScreen>
|
||||
return;
|
||||
}
|
||||
final pendingProvider = AuthTokenStore.getPendingProvider();
|
||||
final provider = pendingProvider ?? AuthTokenStore.getProvider();
|
||||
if (provider == null || !provider.toLowerCase().contains('ory')) {
|
||||
return;
|
||||
}
|
||||
final provider = pendingProvider ?? AuthTokenStore.getProvider() ?? 'ory';
|
||||
|
||||
try {
|
||||
await AuthProxyService.checkCookieSession();
|
||||
@@ -657,7 +654,7 @@ class _LoginScreenState extends ConsumerState<LoginScreen>
|
||||
if (mounted) Navigator.of(context).pop();
|
||||
|
||||
if (redirectTo != null && redirectTo.isNotEmpty) {
|
||||
html.window.location.href = redirectTo;
|
||||
webWindow.redirectTo(redirectTo);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -885,6 +882,24 @@ class _LoginScreenState extends ConsumerState<LoginScreen>
|
||||
debugPrint("[Auth] Failed to pre-fetch profile: $e");
|
||||
}
|
||||
|
||||
if (_loginChallenge != null && _loginChallenge!.isNotEmpty) {
|
||||
try {
|
||||
final res = await AuthProxyService.acceptOidcLogin(
|
||||
_loginChallenge!,
|
||||
token: token,
|
||||
);
|
||||
final redirectTo = res['redirectTo'] as String?;
|
||||
if (redirectTo != null && redirectTo.isNotEmpty) {
|
||||
debugPrint("[Auth] OIDC login accepted. Redirecting to: $redirectTo");
|
||||
webWindow.redirectTo(redirectTo);
|
||||
return;
|
||||
}
|
||||
} catch (e) {
|
||||
_showError("OIDC 로그인 처리에 실패했습니다. 다시 시도해 주세요.");
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if (WebAuthIntegration.isPopup()) {
|
||||
debugPrint("[Auth] Popup detected. Notifying opener and attempting to close.");
|
||||
WebAuthIntegration.sendLoginSuccess(token);
|
||||
|
||||
@@ -16,6 +16,7 @@ class _QRScanScreenState extends State<QRScanScreen> {
|
||||
final _log = Logger('QRScanScreen');
|
||||
final MobileScannerController controller = MobileScannerController(
|
||||
detectionSpeed: DetectionSpeed.noDuplicates,
|
||||
autoStart: false,
|
||||
);
|
||||
bool _isScanned = false;
|
||||
bool _isCheckingSession = false;
|
||||
@@ -28,6 +29,9 @@ class _QRScanScreenState extends State<QRScanScreen> {
|
||||
void initState() {
|
||||
super.initState();
|
||||
_bootstrapCookieSession();
|
||||
WidgetsBinding.instance.addPostFrameCallback((_) {
|
||||
_startScannerIfNeeded();
|
||||
});
|
||||
}
|
||||
|
||||
Future<bool> _bootstrapCookieSession() async {
|
||||
@@ -52,6 +56,28 @@ class _QRScanScreenState extends State<QRScanScreen> {
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> _startScannerIfNeeded() async {
|
||||
if (controller.value.isRunning || controller.value.isStarting) {
|
||||
return;
|
||||
}
|
||||
try {
|
||||
await controller.start();
|
||||
} catch (e) {
|
||||
_log.warning('Scanner start failed: $e');
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> _stopScannerIfRunning() async {
|
||||
if (!controller.value.isRunning && !controller.value.isStarting) {
|
||||
return;
|
||||
}
|
||||
try {
|
||||
await controller.stop();
|
||||
} catch (e) {
|
||||
_log.warning('Scanner stop failed: $e');
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
controller.dispose();
|
||||
@@ -65,6 +91,7 @@ class _QRScanScreenState extends State<QRScanScreen> {
|
||||
for (final barcode in barcodes) {
|
||||
if (barcode.rawValue != null) {
|
||||
_isScanned = true;
|
||||
await _stopScannerIfRunning();
|
||||
if (mounted) {
|
||||
setState(() => _isProcessing = true);
|
||||
}
|
||||
@@ -142,14 +169,14 @@ class _QRScanScreenState extends State<QRScanScreen> {
|
||||
_isSuccess = null;
|
||||
_resultMessage = null;
|
||||
});
|
||||
controller.start();
|
||||
_startScannerIfNeeded();
|
||||
}
|
||||
|
||||
Future<void> _requestCameraPermission() async {
|
||||
if (_isRequestingCamera) return;
|
||||
setState(() => _isRequestingCamera = true);
|
||||
try {
|
||||
await controller.start();
|
||||
await _startScannerIfNeeded();
|
||||
} catch (e) {
|
||||
_log.warning('Camera permission request failed: $e');
|
||||
if (mounted) {
|
||||
|
||||
@@ -791,6 +791,23 @@ class _DashboardScreenState extends ConsumerState<DashboardScreen> {
|
||||
);
|
||||
}
|
||||
|
||||
if (activities.isEmpty) {
|
||||
return Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text(
|
||||
'연동된 RP가 없습니다.',
|
||||
style: TextStyle(fontSize: 14, color: Colors.grey[700], fontWeight: FontWeight.w600),
|
||||
),
|
||||
const SizedBox(height: 6),
|
||||
Text(
|
||||
'RP를 연동하면 최근 활동과 상태가 표시됩니다.',
|
||||
style: TextStyle(fontSize: 12, color: Colors.grey[600]),
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
return grid;
|
||||
},
|
||||
);
|
||||
@@ -815,33 +832,6 @@ class _DashboardScreenState extends ConsumerState<DashboardScreen> {
|
||||
);
|
||||
}
|
||||
|
||||
items.addAll([
|
||||
_ActivityItem(
|
||||
appName: 'BEPs',
|
||||
lastAuthAt: '연동 필요',
|
||||
status: '미연동',
|
||||
canLogout: false,
|
||||
),
|
||||
_ActivityItem(
|
||||
appName: 'KNGIL',
|
||||
lastAuthAt: '연동 필요',
|
||||
status: '미연동',
|
||||
canLogout: false,
|
||||
),
|
||||
_ActivityItem(
|
||||
appName: 'C.E.L',
|
||||
lastAuthAt: '연동 필요',
|
||||
status: '미연동',
|
||||
canLogout: false,
|
||||
),
|
||||
_ActivityItem(
|
||||
appName: 'EG-BIM',
|
||||
lastAuthAt: '연동 필요',
|
||||
status: '미연동',
|
||||
canLogout: false,
|
||||
),
|
||||
]);
|
||||
|
||||
return items;
|
||||
}
|
||||
|
||||
|
||||
64
userfront/test/error_screen_test.dart
Normal file
64
userfront/test/error_screen_test.dart
Normal file
@@ -0,0 +1,64 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:userfront/features/auth/presentation/error_screen.dart';
|
||||
|
||||
Future<void> _pumpErrorScreen(
|
||||
WidgetTester tester, {
|
||||
String? errorCode,
|
||||
String? description,
|
||||
bool? isProdOverride,
|
||||
}) async {
|
||||
await tester.pumpWidget(
|
||||
MaterialApp(
|
||||
home: ErrorScreen(
|
||||
errorCode: errorCode,
|
||||
description: description,
|
||||
isProdOverride: isProdOverride,
|
||||
),
|
||||
),
|
||||
);
|
||||
await tester.pump();
|
||||
}
|
||||
|
||||
void main() {
|
||||
testWidgets('개발환경은 원문 메시지를 노출한다', (WidgetTester tester) async {
|
||||
await _pumpErrorScreen(
|
||||
tester,
|
||||
errorCode: 'custom_error',
|
||||
description: '원문 메시지',
|
||||
isProdOverride: false,
|
||||
);
|
||||
|
||||
expect(find.text('오류: custom_error'), findsOneWidget);
|
||||
expect(find.text('원문 메시지'), findsOneWidget);
|
||||
expect(find.text('오류 종류: custom_error'), findsOneWidget);
|
||||
});
|
||||
|
||||
testWidgets('프로덕션은 whitelist 메시지를 노출한다', (WidgetTester tester) async {
|
||||
await _pumpErrorScreen(
|
||||
tester,
|
||||
errorCode: 'settings_disabled',
|
||||
description: '원문 메시지',
|
||||
isProdOverride: true,
|
||||
);
|
||||
|
||||
expect(find.text('인증 과정에서 오류가 발생했습니다'), findsOneWidget);
|
||||
expect(find.text('현재 계정 설정 화면은 준비 중입니다.'), findsOneWidget);
|
||||
expect(find.text('원문 메시지'), findsNothing);
|
||||
expect(find.text('오류 종류: settings_disabled'), findsOneWidget);
|
||||
});
|
||||
|
||||
testWidgets('프로덕션은 비허용 에러를 unknown_error로 처리한다', (WidgetTester tester) async {
|
||||
await _pumpErrorScreen(
|
||||
tester,
|
||||
errorCode: 'weird_error',
|
||||
description: '원문 메시지',
|
||||
isProdOverride: true,
|
||||
);
|
||||
|
||||
expect(find.text('인증 과정에서 오류가 발생했습니다'), findsOneWidget);
|
||||
expect(find.text('에러가 계속되면 관리자에게 문의해주세요'), findsOneWidget);
|
||||
expect(find.text('원문 메시지'), findsNothing);
|
||||
expect(find.text('오류 종류: unknown_error'), findsOneWidget);
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user