Ejemplo n.º 1
0
        public async Task <ActionResult> GetTopicUpdate(string topic)
        {
            if (String.Equals(ACAPYConstants.PresentationsTopic, topic, StringComparison.InvariantCultureIgnoreCase) == false)
            {
                _logger.LogDebug($"Skipping webhook for topic [{topic}]");
                return(Ok());
            }

            string payload;

            using (var reader = new StreamReader(Request.Body, Encoding.UTF8))
            {
                payload = await reader.ReadToEndAsync();
            }
            _logger.LogInformation($"Topic [{topic}], Payload [{payload}]");

            try
            {
                var update = JsonConvert.DeserializeObject <PresentationUpdate>(payload);

                if (update.State != ACAPYConstants.SuccessfulPresentationUpdate)
                {
                    return(Ok());
                }

                var proof = update.Presentation["requested_proof"].ToObject <RequestedProof>();
                var partialPresentation = new PartialPresentation
                {
                    RequestedProof = proof
                };

                await _sessionStorageService.SatisfyPresentationRequestIdAsync(update.ThreadId, partialPresentation);
            }
            catch (Exception e)
            {
                _logger.LogError(e, "Failed to deserialize a payload");
            }

            return(Ok());
        }
Ejemplo n.º 2
0
        public async Task <bool> SatisfyPresentationRequestIdAsync(string presentationRequestId, PartialPresentation partialPresentation)
        {
            var session = await _context.Sessions.FirstOrDefaultAsync(x => x.PresentationRequestId == presentationRequestId);

            if (session == null)
            {
                _logger.LogWarning($"Couldn't find a corresponding auth session to satisfy. Presentation request id: [{presentationRequestId}]");
                return(false);
            }

            session.PresentationRequestSatisfied = true;
            session.Presentation = partialPresentation;

            _context.Sessions.Update(session);
            return(await _context.SaveChangesAsync() == 1);
        }
Ejemplo n.º 3
0
        public async Task <string> IssueJwtAsync(int lifetime, string issuer, string presentationRecordId, PartialPresentation presentation)
        {
            var claims = new List <Claim>
            {
                new Claim(IdentityConstants.PresentationRequestConfigIDParamName, presentationRecordId),
                new Claim("amr", IdentityConstants.VCAuthnScopeName)
            };

            var presentationConfig = await _presentationConfigurationService.GetAsync(presentationRecordId);

            foreach (var attr in presentation.RequestedProof.RevealedAttributes)
            {
                claims.Add(new Claim(attr.Key, attr.Value.Raw));
                if (string.Equals(attr.Key, presentationConfig.SubjectIdentifier, StringComparison.InvariantCultureIgnoreCase))
                {
                    claims.Add(new Claim("sub", attr.Value.Raw));
                }
            }

            var token = new Token
            {
                CreationTime = _clock.UtcNow.UtcDateTime,
                Issuer       = issuer,
                Lifetime     = lifetime,
                Claims       = new HashSet <Claim>(claims, new ClaimComparer())
            };

            return(await _tokenCreation.CreateTokenAsync(token));
        }