login method
Implementation
Future<void> login([AuthClientLoginOptions? options]) async {
key ??= await Ed25519KeyIdentity.generate(null);
// Create the URL of the IDP. (e.g. https://XXXX/#authorize)
final payload = _createAuthPayload(options);
final result = await authFunction(payload);
final parsedResult = Uri.parse(result);
if ((parsedResult.queryParameters['success'] is String &&
parsedResult.queryParameters['success'] == 'false') ||
parsedResult.queryParameters['success'] == null) {
if (parsedResult.queryParameters['json'] == null) {
final data = parsedResult.queryParameters['data'];
final decoded = cborDecode<Map>((data as String).toU8a());
handleFailure(jsonEncode(decoded), options?.onError);
} else {
handleFailure(
jsonEncode(parsedResult.queryParameters['json']),
options?.onError,
);
}
} else if (parsedResult.queryParameters['json'] == null) {
final data = parsedResult.queryParameters['data'];
final decoded = cborDecode<Map>((data as String).toU8a());
final message = Map<String, dynamic>.from(decoded);
final delegations = message['delegations'] as List;
final delegationList = delegations
.map(
(e) => DelegationWithSignature(
delegation: Delegation.fromJson(e['delegation']),
signature: Uint8List.fromList(e['signature']),
),
)
.toList();
final userPublicKey = Uint8List.fromList(message['userPublicKey']);
final response = AuthResponseSuccess(
delegations: delegationList,
userPublicKey: userPublicKey,
);
handleSuccess(response, options?.onSuccess);
} else {
final data = parsedResult.queryParameters['json'];
final message = Map<String, dynamic>.from(jsonDecode(data as String));
final delegationChain = DelegationChain.fromJSON(message);
chain = delegationChain;
identity = DelegationIdentity.fromDelegation(key!, chain!);
options?.onSuccess?.call();
}
}