Skip to content

Commit

Permalink
token container
Browse files Browse the repository at this point in the history
  • Loading branch information
frankmer committed Sep 16, 2024
1 parent 4b2c929 commit 59eb664
Show file tree
Hide file tree
Showing 41 changed files with 922 additions and 1,827 deletions.
2 changes: 1 addition & 1 deletion integration_test/views_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ Future<void> _settingsViewTest(WidgetTester tester) async {
expect(find.text(AppLocalizationsEn().errorLogTitle), findsOneWidget);
expect(find.byType(SettingsGroup), findsNWidgets(6));
const qrCode =
'otpauth://pipush/label?url=http%3A%2F%2Fwww.example.com&ttl=10&issuer=issuer&enrollment_credential=enrollmentCredentials&v=1&serial=serial&serial=serial&sslverify=0';
'otpauth://pipush/label?url=http%3A%2F%2Fwww.example.com&ttl=10&issuer=issuer&enrollment_container=enrollmentCredentials&v=1&serial=serial&serial=serial&sslverify=0';
final notifier = globalRef!.read(tokenProvider.notifier);
await scanQrCode([notifier], qrCode);

Expand Down
16 changes: 8 additions & 8 deletions lib/api/token_container_api_endpoint.dart
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ import 'package:privacyidea_authenticator/utils/privacyidea_io_client.dart';
import '../l10n/app_localizations.dart';
import '../model/riverpod_states/token_state.dart';
import '../model/token_template.dart';
import '../model/tokens/container_credentials.dart';
import '../model/token_container.dart';
import '../model/tokens/token.dart';
import '../utils/globals.dart';
import '../utils/identifiers.dart';
Expand All @@ -48,7 +48,7 @@ class PrivacyideaContainerApi {
const PrivacyideaContainerApi({required PrivacyideaIOClient ioClient}) : _ioClient = ioClient;

// Returns a tuple of updated/new tokens and serials of deleted tokens
Future<(List<Token>, List<String>)?> sync(ContainerCredentialFinalized container, TokenState tokenState) async {
Future<(List<Token>, List<String>)?> sync(TokenContainerFinalized container, TokenState tokenState) async {
final containerTokenTemplates = tokenState.containerTokens(container.serial).toTemplates();
final maybePiTokensTemplates = tokenState.maybePiTokens.toTemplates();

Expand Down Expand Up @@ -105,7 +105,7 @@ class PrivacyideaContainerApi {
return ([...updatedTokens, ...newTokens], deleteSerials);
}

Future<Response?> finalizeContainer(ContainerCredentialUnfinalized container, EccUtils eccUtils) async {
Future<Response?> finalizeContainer(TokenContainerUnfinalized container, EccUtils eccUtils) async {
final ecPrivateClientKey = container.ecPrivateClientKey;
if (ecPrivateClientKey == null) return null;

Expand All @@ -131,7 +131,7 @@ class PrivacyideaContainerApi {
////// PRIVATE FUNCTIONS //////
////////////////////////////// */

Future<ContainerChallenge?> _getChallenge(ContainerCredentialFinalized container) async {
Future<ContainerChallenge?> _getChallenge(TokenContainerFinalized container) async {
final initResponse = await _ioClient.doGet(url: container.syncUrl, parameters: {CONTAINER_SERIAL: container.serial});
if (initResponse.statusCode != 200) {
_showSyncStatusMessage(initResponse);
Expand All @@ -153,7 +153,7 @@ class PrivacyideaContainerApi {
}

Future<Map<String, dynamic>?> _getContainerDict({
required ContainerCredentialFinalized container,
required TokenContainerFinalized container,
required ContainerChallenge challenge,
required List<Map> otpAuthMaps,
}) async {
Expand Down Expand Up @@ -216,7 +216,7 @@ class PrivacyideaContainerApi {
return jsonDecode(utf8.decode(decryptedContainerDict)) as Map<String, dynamic>;
}

Future<List<Token>> _parseNewTokens({required ContainerCredentialFinalized container, required List<Uri> otpAuthUris}) async {
Future<List<Token>> _parseNewTokens({required TokenContainerFinalized container, required List<Uri> otpAuthUris}) async {
final newTokens = <Token>[];
for (var otpAuthUri in otpAuthUris) {
Logger.debug('Processing token: $otpAuthUri');
Expand All @@ -232,7 +232,7 @@ class PrivacyideaContainerApi {
List<TokenTemplate> _handleMaybePiTokens({
required List<TokenTemplate> maybePiTokensTemplates,
required List<Map<String, dynamic>> serverTokensWithOtps,
required ContainerCredentialFinalized container,
required TokenContainerFinalized container,
}) {
final merged = <TokenTemplate>[];
for (var serverTokenWithOtp in serverTokensWithOtps) {
Expand All @@ -258,7 +258,7 @@ class PrivacyideaContainerApi {
(List<TokenTemplate>, List<String>) _handlePiTokens({
required List<TokenTemplate> containerTokenTemplates,
required List<Map<String, dynamic>> serverTokensWithSerial,
required ContainerCredentialFinalized container,
required TokenContainerFinalized container,
}) {
final deleteSerials = <String>[];
final mergedTemplatesWithSerial = <TokenTemplate>[];
Expand Down
2 changes: 1 addition & 1 deletion lib/interfaces/api_endpoint.dart
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,5 @@ import '../utils/privacyidea_io_client.dart';
abstract class ApiEndpioint<Credential, Data> {
ApiEndpioint(PrivacyideaIOClient ioClient);
Future<Data> fetch();
Future<Data> sync(Credential credential, Data data);
Future<Data> sync(Credential container, Data data);
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,14 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import '../../model/riverpod_states/credentials_state.dart';
import '../../model/tokens/container_credentials.dart';
import '../../model/riverpod_states/token_container_state.dart';
import '../../model/token_container.dart';

abstract class ContainerCredentialsRepository {
Future<CredentialsState> saveCredential(ContainerCredential credential);
Future<CredentialsState> saveCredentialsState(CredentialsState credentialsState);
Future<CredentialsState> loadCredentialsState();
Future<ContainerCredential?> loadCredential(String serial);
Future<CredentialsState> deleteAllCredentials();
Future<CredentialsState> deleteCredential(String serial);
abstract class TokenContainerRepository {
Future<TokenContainerState> saveCredential(TokenContainer container);
Future<TokenContainerState> saveCredentialsState(TokenContainerState containerState);
Future<TokenContainerState> loadCredentialsState();
Future<TokenContainer?> loadCredential(String serial);
Future<TokenContainerState> deleteAllCredentials();
Future<TokenContainerState> deleteCredential(String serial);
}
50 changes: 0 additions & 50 deletions lib/model/riverpod_states/credentials_state.dart

This file was deleted.

Loading

0 comments on commit 59eb664

Please sign in to comment.