0
Fork 0
mirror of https://github.com/immich-app/immich.git synced 2025-01-07 00:50:23 -05:00
immich/mobile/lib/modules/login/services/oauth.service.dart
Robert Vollmer bc3979029d
refactor(mobile): move error details to separate DB column (#6898)
* Add "details" column to LoggerMessage

* Include error details in log details page

* Move error details out of log message

* Add error message to mixin

* Create extension for HTTP Response logging

* Fix analyze errors

* format

* fix analyze errors, format again
2024-02-23 21:38:57 -06:00

43 lines
1.1 KiB
Dart

import 'package:immich_mobile/shared/services/api.service.dart';
import 'package:logging/logging.dart';
import 'package:openapi/api.dart';
import 'package:flutter_web_auth/flutter_web_auth.dart';
// Redirect URL = app.immich://
class OAuthService {
final ApiService _apiService;
final callbackUrlScheme = 'app.immich';
final log = Logger('OAuthService');
OAuthService(this._apiService);
Future<String?> getOAuthServerUrl(
String serverUrl,
) async {
// Resolve API server endpoint from user provided serverUrl
await _apiService.resolveAndSetEndpoint(serverUrl);
final dto = await _apiService.oAuthApi.startOAuth(
OAuthConfigDto(redirectUri: '$callbackUrlScheme:/'),
);
return dto?.url;
}
Future<LoginResponseDto?> oAuthLogin(String oauthUrl) async {
try {
var result = await FlutterWebAuth.authenticate(
url: oauthUrl,
callbackUrlScheme: callbackUrlScheme,
);
return await _apiService.oAuthApi.finishOAuth(
OAuthCallbackDto(
url: result,
),
);
} catch (e, stack) {
log.severe("OAuth login failed", e, stack);
return null;
}
}
}