diff --git a/lib/model/tokens/token.dart b/lib/model/tokens/token.dart index 6d55e8cea..03b868627 100644 --- a/lib/model/tokens/token.dart +++ b/lib/model/tokens/token.dart @@ -39,9 +39,7 @@ abstract class Token with SortableMixin { if (TokenTypes.STEAM.isName(type, caseSensitive: false)) return SteamToken.fromJson(json); throw ArgumentError.value(json, 'Token#fromJson', 'Token type [$type] is not a supported'); } - factory Token.fromUriMap( - Map uriMap, - ) { + factory Token.fromUriMap(Map uriMap) { String type = uriMap[URI_TYPE]; if (TokenTypes.HOTP.isName(type, caseSensitive: false)) return HOTPToken.fromUriMap(uriMap); if (TokenTypes.TOTP.isName(type, caseSensitive: false)) return TOTPToken.fromUriMap(uriMap); diff --git a/lib/processors/scheme_processors/token_import_scheme_processors/otp_auth_processor.dart b/lib/processors/scheme_processors/token_import_scheme_processors/otp_auth_processor.dart index 8e644ba0a..a8203d57b 100644 --- a/lib/processors/scheme_processors/token_import_scheme_processors/otp_auth_processor.dart +++ b/lib/processors/scheme_processors/token_import_scheme_processors/otp_auth_processor.dart @@ -2,6 +2,7 @@ import 'dart:typed_data'; import 'package:collection/collection.dart'; import 'package:privacyidea_authenticator/model/extensions/enums/token_origin_source_type.dart'; +import 'package:privacyidea_authenticator/model/token_import/token_origin_data.dart'; import '../../../model/enums/token_origin_source_type.dart'; import '../../../l10n/app_localizations.dart'; @@ -213,15 +214,7 @@ Map _parseOtpAuth(Uri uri) { } // Parse creator. - final origin = TokenOriginSourceType.unknown.toTokenOrigin( - data: uri.toString(), - originName: getCurrentAppName(), - // If creator is present, it is a privacyIDEA token. If not it could be from an old version of the server too. - isPrivacyIdeaToken: queryParameters['creator'] != null ? true : null, - creator: queryParameters['creator'], - createdAt: DateTime.now(), - ); - uriMap[URI_ORIGIN] = origin; + uriMap[URI_ORIGIN] = _parseCreatorToOrigin(uri); return uriMap; } @@ -362,9 +355,24 @@ Map _parsePiPushToken(Uri uri) { uriMap[URI_PIN] = true; } + // Parse creator. + uriMap[URI_ORIGIN] = _parseCreatorToOrigin(uri); + return uriMap; } +TokenOriginData _parseCreatorToOrigin(Uri uri) { + final origin = TokenOriginSourceType.unknown.toTokenOrigin( + data: uri.toString(), + originName: getCurrentAppName(), + // If creator is present, it is a privacyIDEA token. If not it could be from an old version of the server too. + isPrivacyIdeaToken: uri.queryParameters['creator'] != null ? true : null, + creator: uri.queryParameters['creator'], + createdAt: DateTime.now(), + ); + return origin; +} + /// Parse the label and the issuer (if it exists) from the url. (String, String) _parseLabelAndIssuer(Uri uri) { String label = ''; diff --git a/test/unit_test/model/push_request_test.dart b/test/unit_test/model/push_request_test.dart index 9f330c3d4..e9862c056 100644 --- a/test/unit_test/model/push_request_test.dart +++ b/test/unit_test/model/push_request_test.dart @@ -183,7 +183,7 @@ void _testPushRequest() { "sortIndex": 2, "origin": { "source": "qrScan", - "originName": "privacyIDEA Authenticator", + "appName": "privacyIDEA Authenticator", "data": "otpauth://pipush/PIPU00064CF0?url=https%3A//192.168.56.103/ttype/push&ttl=10&issuer=privacyIDEA&enrollment_credential=9d3100908d3c76a948b6041c8338def8b15ec06a&v=1&serial=PIPU00064CF0&sslverify=0", "isPrivacyIdeaToken": null, @@ -241,7 +241,7 @@ void _testPushRequest() { "sortIndex": 2, "origin": { "source": "qrScan", - "originName": "privacyIDEA Authenticator", + "appName": "privacyIDEA Authenticator", "data": "otpauth://pipush/PIPU00064CF0?url=https%3A//192.168.56.103/ttype/push&ttl=10&issuer=privacyIDEA&enrollment_credential=9d3100908d3c76a948b6041c8338def8b15ec06a&v=1&serial=PIPU00064CF0&sslverify=0", "isPrivacyIdeaToken": null,