Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
b35f495537 | ||
|
|
346ca75d68 | ||
|
|
0c27c10a2c | ||
|
|
ff5df30c53 | ||
|
|
0a6e9de4a8 | ||
|
|
4c377b19c4 | ||
|
|
8494b4ad7f | ||
|
|
e596b99e39 |
+5
-4
@@ -13,11 +13,12 @@ pubspec.lock
|
||||
*.gr.dart
|
||||
*.mocks.dart
|
||||
|
||||
# Keep version.g.dart - it's generated but should be committed
|
||||
# so CI/CD builds have version info without running the generator
|
||||
# Other *.g.dart files (from json_serializable, etc.) are ignored
|
||||
# All generated *.g.dart files (from json_serializable, riverpod, version_builder)
|
||||
# These are regenerated by build_runner during CI/CD builds
|
||||
lib/**/*.g.dart
|
||||
!lib/version.g.dart
|
||||
|
||||
# Generated health.json (regenerated by tool/generate_health_json.dart during build)
|
||||
web/health.json
|
||||
|
||||
# IDE
|
||||
.idea/
|
||||
|
||||
@@ -7,6 +7,49 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
||||
|
||||
## [Unreleased]
|
||||
|
||||
## [1.0.11] - 2026-01-04
|
||||
|
||||
### Changed
|
||||
- Web auth now extracts user info directly from JWT instead of syncing with core-api
|
||||
- Eliminates CORS preflight issues with /auth/sync endpoint
|
||||
- Decodes JWT claims (name, email, groups) client-side
|
||||
- Bearer token will be used for API authentication
|
||||
|
||||
## [1.0.10] - 2026-01-04
|
||||
|
||||
### Fixed
|
||||
- Fixed OIDC callback route being redirected to login before processing
|
||||
- Moved callback route exception check BEFORE the auth redirect check in router
|
||||
- This was preventing token exchange from ever happening
|
||||
- Added favicon.ico to web root for proper browser tab icon display
|
||||
|
||||
## [1.0.9] - 2026-01-04
|
||||
|
||||
### Fixed
|
||||
- Fixed OIDC callback Riverpod state modification error
|
||||
- Deferred callback processing to `addPostFrameCallback` to avoid modifying state during widget build
|
||||
|
||||
## [1.0.8] - 2026-01-04
|
||||
|
||||
### Changed
|
||||
- Switched from hash-based URLs (`/#/login`) to path-based URLs (`/login`)
|
||||
- Required for OIDC callback to work correctly
|
||||
- Uses conditional import to avoid breaking mobile/desktop builds
|
||||
|
||||
## [1.0.7] - 2026-01-04
|
||||
|
||||
### Fixed
|
||||
- Fixed OIDC PKCE state loss across browser redirect
|
||||
- Code verifier and state now persist in sessionStorage instead of memory
|
||||
- Prevents "No code verifier" error after Authentik redirect
|
||||
|
||||
## [1.0.6] - 2026-01-04
|
||||
|
||||
### Fixed
|
||||
- Fixed version generation in CI/CD builds
|
||||
- Removed generated files (version.g.dart, health.json) from git tracking
|
||||
- These files are now regenerated from pubspec.yaml during Docker build
|
||||
|
||||
## [1.0.5] - 2026-01-04
|
||||
|
||||
### Changed
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import 'dart:convert';
|
||||
import 'dart:convert' show base64Url, jsonDecode, jsonEncode, utf8;
|
||||
import 'dart:developer' as developer;
|
||||
|
||||
import 'package:flutter/foundation.dart' show kIsWeb;
|
||||
@@ -265,23 +265,27 @@ class AuthNotifier extends _$AuthNotifier {
|
||||
final oidcService = OidcServiceWeb();
|
||||
final tokens = await oidcService.exchangeCode(code, callbackState);
|
||||
|
||||
// Step 2: Sync with core-api to get user profile and roles
|
||||
developer.log('Syncing with core-api', name: 'auth');
|
||||
final authDatasource = ref.read(authDatasourceProvider);
|
||||
final syncResponse = await authDatasource.syncUser(tokens.accessToken);
|
||||
// Step 2: Decode JWT to extract user info (skip core-api sync)
|
||||
final claims = _decodeJwtClaims(tokens.accessToken);
|
||||
final userName = claims['name'] as String? ??
|
||||
claims['preferred_username'] as String? ??
|
||||
'User';
|
||||
final userEmail = claims['email'] as String? ?? '';
|
||||
final authentikId = claims['sub'] as String?;
|
||||
final groups = (claims['groups'] as List<dynamic>?)?.cast<String>() ?? [];
|
||||
|
||||
// Step 3: Store credentials and user data
|
||||
developer.log('JWT claims: name=$userName, email=$userEmail, groups=$groups', name: 'auth');
|
||||
|
||||
// Step 3: Store credentials and user data from JWT
|
||||
await _storeAuth(
|
||||
accessToken: tokens.accessToken,
|
||||
refreshToken: tokens.refreshToken,
|
||||
expiresAt: tokens.expiresAt,
|
||||
userId: syncResponse.userId,
|
||||
authentikId: syncResponse.authentikId,
|
||||
userName: syncResponse.name,
|
||||
userEmail: syncResponse.email,
|
||||
avatarUrl: syncResponse.avatarUrl,
|
||||
roles: syncResponse.roles,
|
||||
preferences: syncResponse.preferences,
|
||||
authentikId: authentikId,
|
||||
userName: userName,
|
||||
userEmail: userEmail,
|
||||
// Roles from groups - for now just store group names
|
||||
// Full role parsing can be done later if needed
|
||||
);
|
||||
|
||||
state = AsyncData(AuthState(
|
||||
@@ -289,19 +293,12 @@ class AuthNotifier extends _$AuthNotifier {
|
||||
accessToken: tokens.accessToken,
|
||||
refreshToken: tokens.refreshToken,
|
||||
expiresAt: tokens.expiresAt,
|
||||
userId: syncResponse.userId,
|
||||
authentikId: syncResponse.authentikId,
|
||||
userName: syncResponse.name,
|
||||
userEmail: syncResponse.email,
|
||||
avatarUrl: syncResponse.avatarUrl,
|
||||
roles: syncResponse.roles,
|
||||
preferences: syncResponse.preferences,
|
||||
authentikId: authentikId,
|
||||
userName: userName,
|
||||
userEmail: userEmail,
|
||||
));
|
||||
|
||||
developer.log(
|
||||
'Authenticated as ${syncResponse.name} with ${syncResponse.roles.length} roles',
|
||||
name: 'auth',
|
||||
);
|
||||
developer.log('Authenticated as $userName', name: 'auth');
|
||||
|
||||
// Clean up the URL by removing the query parameters
|
||||
web_utils.replaceUrl('/');
|
||||
@@ -314,6 +311,35 @@ class AuthNotifier extends _$AuthNotifier {
|
||||
}
|
||||
}
|
||||
|
||||
/// Decode JWT payload without verification (validation happens server-side).
|
||||
Map<String, dynamic> _decodeJwtClaims(String jwt) {
|
||||
try {
|
||||
final parts = jwt.split('.');
|
||||
if (parts.length != 3) {
|
||||
developer.log('Invalid JWT format', name: 'auth');
|
||||
return {};
|
||||
}
|
||||
|
||||
// Decode the payload (second part)
|
||||
String payload = parts[1];
|
||||
// Add padding if needed for base64
|
||||
switch (payload.length % 4) {
|
||||
case 2:
|
||||
payload += '==';
|
||||
break;
|
||||
case 3:
|
||||
payload += '=';
|
||||
break;
|
||||
}
|
||||
|
||||
final decoded = utf8.decode(base64Url.decode(payload));
|
||||
return jsonDecode(decoded) as Map<String, dynamic>;
|
||||
} catch (e) {
|
||||
developer.log('Failed to decode JWT: $e', name: 'auth');
|
||||
return {};
|
||||
}
|
||||
}
|
||||
|
||||
/// Sign out and clear stored credentials.
|
||||
Future<void> signOut() async {
|
||||
await _clearStoredAuth();
|
||||
|
||||
@@ -8,6 +8,7 @@ import 'package:dio/dio.dart';
|
||||
|
||||
import '../config/app_config.dart';
|
||||
import 'oidc_service.dart';
|
||||
import 'web_utils.dart' as web_utils;
|
||||
|
||||
/// Web implementation of OIDC service using browser redirect flow.
|
||||
///
|
||||
@@ -25,9 +26,9 @@ class OidcServiceWeb implements OidcService {
|
||||
/// Redirect URI for web.
|
||||
static String get _redirectUri => '${AppConfig.webBaseUrl}/callback';
|
||||
|
||||
// PKCE state stored during auth flow (in-memory for single-page app)
|
||||
static String? _codeVerifier;
|
||||
static String? _state;
|
||||
// SessionStorage keys for PKCE state (persists across redirect)
|
||||
static const _codeVerifierKey = 'oidc_code_verifier';
|
||||
static const _stateKey = 'oidc_state';
|
||||
|
||||
/// Get the authorization URL to redirect the browser to.
|
||||
///
|
||||
@@ -39,11 +40,15 @@ class OidcServiceWeb implements OidcService {
|
||||
final authEndpoint = discovery['authorization_endpoint'] as String;
|
||||
|
||||
// Generate PKCE code verifier and challenge
|
||||
_codeVerifier = _generateCodeVerifier();
|
||||
final codeChallenge = _generateCodeChallenge(_codeVerifier!);
|
||||
final codeVerifier = _generateCodeVerifier();
|
||||
final codeChallenge = _generateCodeChallenge(codeVerifier);
|
||||
|
||||
// Generate state for CSRF protection
|
||||
_state = _generateRandomString(32);
|
||||
final state = _generateRandomString(32);
|
||||
|
||||
// Store PKCE state in sessionStorage (persists across redirect)
|
||||
web_utils.setSessionStorage(_codeVerifierKey, codeVerifier);
|
||||
web_utils.setSessionStorage(_stateKey, state);
|
||||
|
||||
// Build authorization URL
|
||||
final params = {
|
||||
@@ -53,7 +58,7 @@ class OidcServiceWeb implements OidcService {
|
||||
'scope': _scopes.join(' '),
|
||||
'code_challenge': codeChallenge,
|
||||
'code_challenge_method': 'S256',
|
||||
'state': _state,
|
||||
'state': state,
|
||||
};
|
||||
|
||||
final uri = Uri.parse(authEndpoint).replace(queryParameters: params);
|
||||
@@ -67,12 +72,21 @@ class OidcServiceWeb implements OidcService {
|
||||
/// [code] is the authorization code from the callback URL.
|
||||
/// [state] is the state parameter from the callback URL (verified for CSRF).
|
||||
Future<OidcTokens> exchangeCode(String code, String state) async {
|
||||
// Retrieve PKCE state from sessionStorage
|
||||
final storedState = web_utils.getSessionStorage(_stateKey);
|
||||
final codeVerifier = web_utils.getSessionStorage(_codeVerifierKey);
|
||||
|
||||
developer.log('Stored state: $storedState, received state: $state', name: 'oidc_web');
|
||||
developer.log('Code verifier present: ${codeVerifier != null}', name: 'oidc_web');
|
||||
|
||||
// Verify state matches
|
||||
if (_state == null || state != _state) {
|
||||
if (storedState == null || state != storedState) {
|
||||
_clearPkceState();
|
||||
throw OidcException('State mismatch - possible CSRF attack');
|
||||
}
|
||||
|
||||
if (_codeVerifier == null) {
|
||||
if (codeVerifier == null) {
|
||||
_clearPkceState();
|
||||
throw OidcException('No code verifier - flow not started properly');
|
||||
}
|
||||
|
||||
@@ -91,7 +105,7 @@ class OidcServiceWeb implements OidcService {
|
||||
'client_id': AppConfig.authClientId,
|
||||
'redirect_uri': _redirectUri,
|
||||
'code': code,
|
||||
'code_verifier': _codeVerifier,
|
||||
'code_verifier': codeVerifier,
|
||||
},
|
||||
options: Options(
|
||||
contentType: Headers.formUrlEncodedContentType,
|
||||
@@ -102,8 +116,7 @@ class OidcServiceWeb implements OidcService {
|
||||
developer.log('Token exchange successful', name: 'oidc_web');
|
||||
|
||||
// Clear stored PKCE state
|
||||
_codeVerifier = null;
|
||||
_state = null;
|
||||
_clearPkceState();
|
||||
|
||||
return OidcTokens(
|
||||
accessToken: data['access_token'] as String,
|
||||
@@ -115,14 +128,17 @@ class OidcServiceWeb implements OidcService {
|
||||
);
|
||||
} on DioException catch (e) {
|
||||
developer.log('Token exchange failed: $e', name: 'oidc_web');
|
||||
_clearPkceState();
|
||||
throw OidcException('Token exchange failed: ${e.message}');
|
||||
} finally {
|
||||
// Clear PKCE state on error too
|
||||
_codeVerifier = null;
|
||||
_state = null;
|
||||
}
|
||||
}
|
||||
|
||||
/// Clear PKCE state from sessionStorage.
|
||||
void _clearPkceState() {
|
||||
web_utils.removeSessionStorage(_codeVerifierKey);
|
||||
web_utils.removeSessionStorage(_stateKey);
|
||||
}
|
||||
|
||||
/// Not used on web - use [getAuthorizationUrl] and [exchangeCode] instead.
|
||||
@override
|
||||
Future<OidcTokens> signIn() async {
|
||||
|
||||
@@ -15,3 +15,18 @@ String getCurrentUrl() {
|
||||
void replaceUrl(String url) {
|
||||
throw UnsupportedError('replaceUrl is only supported on web');
|
||||
}
|
||||
|
||||
/// Store a value in sessionStorage (no-op on non-web).
|
||||
void setSessionStorage(String key, String value) {
|
||||
throw UnsupportedError('setSessionStorage is only supported on web');
|
||||
}
|
||||
|
||||
/// Get a value from sessionStorage (no-op on non-web).
|
||||
String? getSessionStorage(String key) {
|
||||
throw UnsupportedError('getSessionStorage is only supported on web');
|
||||
}
|
||||
|
||||
/// Remove a value from sessionStorage (no-op on non-web).
|
||||
void removeSessionStorage(String key) {
|
||||
throw UnsupportedError('removeSessionStorage is only supported on web');
|
||||
}
|
||||
|
||||
@@ -17,3 +17,18 @@ String getCurrentUrl() {
|
||||
void replaceUrl(String url) {
|
||||
web.window.history.replaceState(null, '', url);
|
||||
}
|
||||
|
||||
/// Store a value in sessionStorage.
|
||||
void setSessionStorage(String key, String value) {
|
||||
web.window.sessionStorage.setItem(key, value);
|
||||
}
|
||||
|
||||
/// Get a value from sessionStorage.
|
||||
String? getSessionStorage(String key) {
|
||||
return web.window.sessionStorage.getItem(key);
|
||||
}
|
||||
|
||||
/// Remove a value from sessionStorage.
|
||||
void removeSessionStorage(String key) {
|
||||
web.window.sessionStorage.removeItem(key);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,5 @@
|
||||
/// URL strategy with conditional imports for web/non-web platforms.
|
||||
library;
|
||||
|
||||
export 'url_strategy_stub.dart'
|
||||
if (dart.library.js_interop) 'url_strategy_web.dart';
|
||||
@@ -0,0 +1,4 @@
|
||||
/// Stub for non-web platforms - does nothing.
|
||||
void configureUrlStrategy() {
|
||||
// No-op on mobile/desktop
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
/// Web-specific URL strategy configuration.
|
||||
library;
|
||||
|
||||
import 'package:flutter_web_plugins/url_strategy.dart';
|
||||
|
||||
void configureUrlStrategy() {
|
||||
// Use path-based URLs instead of hash-based (e.g., /login instead of /#/login)
|
||||
// Required for OIDC callback to work properly
|
||||
usePathUrlStrategy();
|
||||
}
|
||||
+5
-5
@@ -4,19 +4,19 @@ import 'package:flutter/material.dart';
|
||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||
|
||||
import 'app.dart';
|
||||
import 'core/config/url_strategy.dart';
|
||||
import 'version.g.dart';
|
||||
|
||||
void main() {
|
||||
WidgetsFlutterBinding.ensureInitialized();
|
||||
|
||||
// Use path-based URLs on web (no-op on mobile/desktop)
|
||||
configureUrlStrategy();
|
||||
|
||||
developer.log(
|
||||
'${AppVersion.name} v${AppVersion.fullVersion}',
|
||||
name: 'tatlock_ui',
|
||||
);
|
||||
|
||||
runApp(
|
||||
const ProviderScope(
|
||||
child: TatlockApp(),
|
||||
),
|
||||
);
|
||||
runApp(const ProviderScope(child: TatlockApp()));
|
||||
}
|
||||
|
||||
@@ -34,6 +34,11 @@ GoRouter appRouter(Ref ref) {
|
||||
return null;
|
||||
}
|
||||
|
||||
// Allow callback route through without auth check (must be checked FIRST!)
|
||||
if (state.matchedLocation == AppRoutes.callback) {
|
||||
return null;
|
||||
}
|
||||
|
||||
final isAuthenticated = authState.value?.isAuthenticated ?? false;
|
||||
final isLoginRoute = state.matchedLocation == AppRoutes.login;
|
||||
|
||||
@@ -47,11 +52,6 @@ GoRouter appRouter(Ref ref) {
|
||||
return AppRoutes.frontHall;
|
||||
}
|
||||
|
||||
// Allow callback route through without auth check
|
||||
if (state.matchedLocation == AppRoutes.callback) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return null;
|
||||
},
|
||||
routes: [
|
||||
@@ -286,7 +286,10 @@ class _OidcCallbackPageState extends ConsumerState<_OidcCallbackPage> {
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
_processCallback();
|
||||
// Defer callback processing to avoid Riverpod state modification during build
|
||||
WidgetsBinding.instance.addPostFrameCallback((_) {
|
||||
_processCallback();
|
||||
});
|
||||
}
|
||||
|
||||
Future<void> _processCallback() async {
|
||||
|
||||
@@ -1,13 +0,0 @@
|
||||
// GENERATED FILE - DO NOT EDIT
|
||||
// Generated by build_runner from pubspec.yaml
|
||||
|
||||
/// Application version information from pubspec.yaml
|
||||
class AppVersion {
|
||||
AppVersion._();
|
||||
|
||||
static const String name = 'tatlock_ui';
|
||||
static const String description = 'Tatlock - a Home Lab AI';
|
||||
static const String version = '1.0.4';
|
||||
static const int buildNumber = 1;
|
||||
static const String fullVersion = '1.0.4+1';
|
||||
}
|
||||
+3
-1
@@ -16,7 +16,7 @@ publish_to: 'none' # Remove this line if you wish to publish to pub.dev
|
||||
# https://developer.apple.com/library/archive/documentation/General/Reference/InfoPlistKeyReference/Articles/CoreFoundationKeys.html
|
||||
# In Windows, build-name is used as the major, minor, and patch parts
|
||||
# of the product and file versions while build-number is used as the build suffix.
|
||||
version: 1.0.5+1
|
||||
version: 1.0.11+1
|
||||
|
||||
environment:
|
||||
sdk: ^3.10.4
|
||||
@@ -30,6 +30,8 @@ environment:
|
||||
dependencies:
|
||||
flutter:
|
||||
sdk: flutter
|
||||
flutter_web_plugins:
|
||||
sdk: flutter
|
||||
|
||||
# State Management
|
||||
flutter_riverpod: ^3.0.0
|
||||
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 4.2 KiB |
@@ -1,8 +0,0 @@
|
||||
{
|
||||
"status": "healthy",
|
||||
"name": "tatlock_ui",
|
||||
"title": "Tatlock - a Home Lab AI",
|
||||
"version": "1.0.4",
|
||||
"buildNumber": 1,
|
||||
"fullVersion": "1.0.4+1"
|
||||
}
|
||||
@@ -27,6 +27,7 @@
|
||||
<link rel="apple-touch-icon" href="icons/Icon-192.png">
|
||||
|
||||
<!-- Favicon -->
|
||||
<link rel="icon" type="image/x-icon" href="favicon.ico"/>
|
||||
<link rel="icon" type="image/png" href="favicon.png"/>
|
||||
|
||||
<title>Tatlock</title>
|
||||
|
||||
Reference in New Issue
Block a user