/// <summary>
        /// https://learn.mattr.global/tutorials/verify/using-callback/callback-e-to-e
        /// </summary>
        /// <param name="callbackBaseUrl"></param>
        /// <returns></returns>
        public async Task <(string QrCodeUrl, string ChallengeId)> CreateVerifyCallback(string callbackBaseUrl)
        {
            callbackBaseUrl = callbackBaseUrl.Trim();
            if (!callbackBaseUrl.EndsWith('/'))
            {
                callbackBaseUrl = $"{callbackBaseUrl}/";
            }

            var callbackUrlFull = $"{callbackBaseUrl}{MATTR_CALLBACK_VERIFY_PATH}";
            var challenge       = GetEncodedRandomString();

            HttpClient client      = _clientFactory.CreateClient();
            var        accessToken = await _mattrTokenApiService.GetApiToken(client, "mattrAccessToken");

            client.DefaultRequestHeaders.Authorization =
                new AuthenticationHeaderValue("Bearer", accessToken);
            client.DefaultRequestHeaders.TryAddWithoutValidation("Content-Type", "application/json");

            var template = await _boInsuranceDbService.GetLastDriverLicensePrsentationTemplate();

            // Invoke the Presentation Request
            var invokePresentationResponse = await InvokePresentationRequest(
                client,
                template.DidId,
                template.TemplateId,
                challenge,
                callbackUrlFull);

            // Request DID
            V1_GetDidResponse did = await RequestDID(template.DidId, client);

            // Sign and Encode the Presentation Request body
            var signAndEncodePresentationRequestBodyResponse = await SignAndEncodePresentationRequestBody(
                client, did, invokePresentationResponse);

            // fix strange DTO
            var jws = signAndEncodePresentationRequestBodyResponse.Replace("\"", "");

            // save to db // TODO add this back once working
            var drivingLicensePresentationVerify = new DrivingLicensePresentationVerify
            {
                DidId       = template.DidId,
                TemplateId  = template.TemplateId,
                CallbackUrl = callbackUrlFull,
                Challenge   = challenge,
                InvokePresentationResponse = JsonConvert.SerializeObject(invokePresentationResponse),
                Did = JsonConvert.SerializeObject(did),
                SignAndEncodePresentationRequestBody = jws
            };
            await _boInsuranceDbService.CreateDrivingLicensePresentationVerify(drivingLicensePresentationVerify);

            var qrCodeUrl = $"didcomm://https://{_mattrConfiguration.TenantSubdomain}/?request={jws}";

            return(qrCodeUrl, challenge);
        }
Ejemplo n.º 2
0
 public async Task CreateDrivingLicensePresentationVerify(DrivingLicensePresentationVerify drivingLicensePresentationVerify)
 {
     _boInsuranceVerifyMattrContext.DrivingLicensePresentationVerifications.Add(drivingLicensePresentationVerify);
     await _boInsuranceVerifyMattrContext.SaveChangesAsync();
 }