Example #1
0
 private void TrustServiceUrls(IdentityToken identityToken, IEnumerable <IActivity> activities)
 {
     // add the service url to the list of trusted urls only if the JwtToken
     // is valid and identity is not null
     if (identityToken.Authenticated && identityToken.Identity != null)
     {
         if (activities.Any())
         {
             foreach (var activity in activities)
             {
                 MicrosoftAppCredentials.TrustServiceUrl(activity?.ServiceUrl);
             }
         }
         else
         {
         }
     }
 }
        public static void ValidateServiceUrlClaim(this IdentityToken token, IEnumerable <IActivity> activities)
        {
            // if token is authenticated, the service url in the activities need to be validated using
            // the service url claim.
            if (token.Authenticated)
            {
                var serviceUrlClaim = token.Identity?.Claims.FirstOrDefault(claim => claim.Type == "serviceurl");

                // if there is a service url claim in the identity claims, check if it matches the service url in the activities
                if (serviceUrlClaim != null && !string.IsNullOrEmpty(serviceUrlClaim.Value))
                {
                    var filteredActivities = activities.Where(activity => string.Compare(activity.ServiceUrl, serviceUrlClaim.Value) != 0);
                    if (filteredActivities.Count() != 0)
                    {
                        throw new ArgumentException($"ServiceUrl claim: {serviceUrlClaim.Value} didn't match activity's ServiceUrl: {string.Join(",", filteredActivities.Select(activity => activity.ServiceUrl))}");
                    }
                }
            }
        }
Example #3
0
        internal void TrustServiceUrls(IdentityToken identityToken, IEnumerable <IActivity> activities)
        {
            // add the service url to the list of trusted urls only if the JwtToken
            // is valid and identity is not null
            if (identityToken.Authenticated && identityToken.Identity != null)
            {
                if (activities.Any())
                {
                    foreach (var activity in activities)
                    {
                        MicrosoftAppCredentials.TrustServiceUrl(activity?.ServiceUrl);
                    }
                }
                else
                {
#if NET45
                    Trace.TraceWarning("No ServiceUrls added to trusted list");
#endif
                }
            }
        }