private ClaimDescriptionList ValidateToken(string authToken)
        {
            var issuer = string.Format(this.settings.TokenIssuerFormat, this.settings.TenantId);

            var validatedClaims = ServerUtility.Validate(
                issuer,
                this.settings.ClusterApplication,
                this.settings.RoleClaimKey,
                this.settings.AdminRoleClaimValue,
                this.settings.UserRoleClaimValue,
                string.Format(this.settings.CertEndpointFormat, this.settings.TenantId),
                TimeSpan.FromSeconds(this.settings.SigningCertRolloverCheckInterval).Ticks,
                authToken);

            var claimsList = new ClaimDescriptionList();
            var claims     = new List <ClaimDescription>();

            var roleClaim = new ClaimDescription(
                this.settings.RoleClaimKey,
                issuer, // issuer
                issuer, // original issuer
                issuer, // subject
                validatedClaims.IsAdmin ? this.settings.AdminRoleClaimValue : this.settings.UserRoleClaimValue,
                "N/A"); // value type

            var expirationClaim = new ClaimDescription(
                ServerUtility.ExpirationClaim,
                issuer, // issuer
                issuer, // original issuer
                issuer, // subject
                validatedClaims.Expiration.TotalSeconds.ToString(),
                "N/A"); // value type

            claims.Add(roleClaim);
            claims.Add(expirationClaim);

            claimsList.AddClaims(claims);

            return(claimsList);
        }
Esempio n. 2
0
        private ClaimDescriptionList ValidateToken(string authToken)
        {
            ClaimDescriptionList     claimList    = new ClaimDescriptionList();
            ClaimsIdentityCollection claimsResult = this.dstsManager.ValidateToken(authToken);
            List <ClaimDescription>  claims       = new List <ClaimDescription>();

            for (int i = 0; i < claimsResult.Count; i++)
            {
                IClaimsIdentity claimIdentity = claimsResult[i];
                foreach (Claim claim in claimIdentity.Claims)
                {
                    ClaimDescription claimDescription = new ClaimDescription(
                        claim.ClaimType,
                        claim.Issuer,
                        claim.OriginalIssuer,
                        claim.Subject.ToString(),
                        claim.Value,
                        claim.ValueType);
                    claims.Add(claimDescription);
                }
            }
            claimList.AddClaims(claims);
            return(claimList);
        }