1
0
forked from baron/baron-sso

userfront 동의 화면 i18n 적용 및 locale 키 추가

This commit is contained in:
2026-03-19 14:42:16 +09:00
parent c8291da699
commit 691d9e5dd6
7 changed files with 266 additions and 36 deletions

View File

@@ -1,5 +1,6 @@
import 'package:flutter/material.dart';
import 'package:go_router/go_router.dart';
import 'package:userfront/i18n.dart';
import 'package:userfront/core/i18n/locale_utils.dart';
import 'package:userfront/core/services/auth_proxy_service.dart';
import 'package:userfront/core/services/web_window.dart';
@@ -19,27 +20,42 @@ class _ConsentScreenState extends State<ConsentScreen> {
bool _isSubmitting = false;
String? _error;
// 사용자가 선택한 스코프 목록
final Set<String> _selectedScopes = {};
// 권한별 설명 매핑 (동적으로 업데이트됨)
final Map<String, String> _scopeDescriptions = {
'openid': 'OpenID 인증 정보 (로그인 상태 확인)',
'profile': '기본 프로필 정보 (이름, 사용자 식별자)',
'email': '이메일 주소 (계정 식별 및 알림 용도)',
'offline_access': '오프라인 접근 (로그인 유지)',
'phone': '휴대폰 번호 (본인 인증 및 알림)',
};
// 필수 권한 목록 (동적으로 업데이트됨)
final Map<String, String> _scopeDescriptions = {};
final Set<String> _mandatoryScopes = {'openid'};
@override
void initState() {
super.initState();
_scopeDescriptions.addAll(_defaultScopeDescriptions());
_fetchConsentInfo();
}
Map<String, String> _defaultScopeDescriptions() {
return {
'openid': tr(
'msg.userfront.consent.scope.openid',
fallback: 'OpenID authentication information (signin session check)',
),
'profile': tr(
'msg.userfront.consent.scope.profile',
fallback: 'Basic profile information (name, user identifier)',
),
'email': tr(
'msg.userfront.consent.scope.email',
fallback: 'Email address (account identification and notifications)',
),
'offline_access': tr(
'msg.userfront.consent.scope.offline_access',
fallback: 'Offline access (keep signed in)',
),
'phone': tr(
'msg.userfront.consent.scope.phone',
fallback: 'Phone number (identity verification and notifications)',
),
};
}
Future<void> _fetchConsentInfo() async {
try {
final info = await AuthProxyService.getConsentInfo(
@@ -90,7 +106,11 @@ class _ConsentScreenState extends State<ConsentScreen> {
});
} catch (e) {
setState(() {
_error = '동의 정보를 불러오는데 실패했습니다: $e';
_error = tr(
'msg.userfront.consent.load_error',
fallback: 'Failed to load consent information: {{error}}',
params: {'error': '$e'},
);
_isLoading = false;
});
}
@@ -112,13 +132,21 @@ class _ConsentScreenState extends State<ConsentScreen> {
webWindow.redirectTo(result['redirectTo']);
} else {
setState(() {
_error = '동의가 처리되었으나, 리다이렉트 URL을 받지 못했습니다.';
_error = tr(
'msg.userfront.consent.missing_redirect',
fallback:
'Consent was processed, but the redirect URL was missing.',
);
_isSubmitting = false;
});
}
} catch (e) {
setState(() {
_error = '동의 처리에 실패했습니다: $e';
_error = tr(
'msg.userfront.consent.accept_error',
fallback: 'Failed to process consent: {{error}}',
params: {'error': '$e'},
);
_isSubmitting = false;
});
}
@@ -128,17 +156,17 @@ class _ConsentScreenState extends State<ConsentScreen> {
final confirmed = await showDialog<bool>(
context: context,
builder: (context) => AlertDialog(
title: const Text('동의 취소'),
content: const Text('권한 동의를 취소하면 해당 서비스를 이용할 수 없습니다. 취소하시겠습니까?'),
title: Text(tr('ui.userfront.consent.cancel.title')),
content: Text(tr('msg.userfront.consent.cancel.confirm')),
actions: [
TextButton(
onPressed: () => Navigator.pop(context, false),
child: const Text('아니오'),
child: Text(tr('ui.common.cancel')),
),
TextButton(
onPressed: () => Navigator.pop(context, true),
style: TextButton.styleFrom(foregroundColor: Colors.red),
child: const Text('예, 취소합니다'),
child: Text(tr('ui.userfront.consent.cancel.confirm_button')),
),
],
),
@@ -159,9 +187,18 @@ class _ConsentScreenState extends State<ConsentScreen> {
} catch (e) {
setState(() => _isSubmitting = false);
if (mounted) {
ScaffoldMessenger.of(
context,
).showSnackBar(SnackBar(content: Text('취소 처리 중 오류가 발생했습니다: $e')));
ScaffoldMessenger.of(context).showSnackBar(
SnackBar(
content: Text(
tr(
'msg.userfront.consent.cancel.error',
fallback:
'An error occurred while cancelling consent: {{error}}',
params: {'error': '$e'},
),
),
),
);
}
}
}
@@ -200,7 +237,9 @@ class _ConsentScreenState extends State<ConsentScreen> {
}
Widget _buildConsentCard(BuildContext context) {
final clientName = _consentInfo?['client']?['client_name'] ?? '알 수 없는 앱';
final clientName =
_consentInfo?['client']?['client_name'] ??
tr('msg.userfront.consent.client_unknown');
final clientId = _consentInfo?['client']?['client_id'] ?? '-';
final clientLogo = _consentInfo?['client']?['logo_uri'];
final requestedScopes =
@@ -223,14 +262,17 @@ class _ConsentScreenState extends State<ConsentScreen> {
crossAxisAlignment: CrossAxisAlignment.stretch,
children: [
// 1. 헤더 영역
const Text(
'접근 권한 요청',
style: TextStyle(fontSize: 24, fontWeight: FontWeight.bold),
Text(
tr('ui.userfront.consent.title'),
style: const TextStyle(
fontSize: 24,
fontWeight: FontWeight.bold,
),
textAlign: TextAlign.center,
),
const SizedBox(height: 12),
Text(
'아래 서비스가 회원님의 계정 정보에 접근하려고 합니다.\n계속 진행하려면 동의 여부를 선택해 주세요.',
tr('msg.userfront.consent.description'),
style: TextStyle(fontSize: 14, color: Colors.grey[600]),
textAlign: TextAlign.center,
),
@@ -277,7 +319,11 @@ class _ConsentScreenState extends State<ConsentScreen> {
),
const SizedBox(height: 4),
Text(
'클라이언트 ID: $clientId',
tr(
'msg.userfront.consent.client_id',
fallback: 'Client ID: {{id}}',
params: {'id': clientId},
),
style: TextStyle(
fontSize: 12,
color: Colors.grey[500],
@@ -296,15 +342,19 @@ class _ConsentScreenState extends State<ConsentScreen> {
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
const Text(
'요청된 권한',
style: TextStyle(
Text(
tr('ui.userfront.consent.requested_scopes'),
style: const TextStyle(
fontSize: 16,
fontWeight: FontWeight.bold,
),
),
Text(
'${requestedScopes.length}',
tr(
'msg.userfront.consent.scope_count',
fallback: 'Total {{count}}',
params: {'count': '${requestedScopes.length}'},
),
style: TextStyle(
fontSize: 14,
color: Theme.of(context).primaryColor,
@@ -367,8 +417,8 @@ class _ConsentScreenState extends State<ConsentScreen> {
color: Colors.white,
),
)
: const Text(
'동의하고 계속하기',
: Text(
tr('ui.userfront.consent.accept'),
style: TextStyle(
fontSize: 16,
fontWeight: FontWeight.bold,
@@ -384,11 +434,11 @@ class _ConsentScreenState extends State<ConsentScreen> {
borderRadius: BorderRadius.circular(8),
),
),
child: const Text('취소'),
child: Text(tr('ui.common.cancel')),
),
const SizedBox(height: 16),
Text(
'동의 후 자동으로 서비스로 이동합니다.',
tr('msg.userfront.consent.redirect_notice'),
style: TextStyle(fontSize: 12, color: Colors.grey[500]),
textAlign: TextAlign.center,
),