/// <summary>
        /// Initializes a new instance of the Sentinel.OAuth.Models.Identity.SentinelPrincipal class.
        /// </summary>
        /// <exception cref="ArgumentNullException">
        /// Thrown when one or more required arguments are null.
        /// </exception>
        /// <param name="identity">The identity.</param>
        public SentinelPrincipal(ISentinelIdentity identity)
        {
            if (identity == null)
            {
                throw new ArgumentNullException("identity");
            }

            this.Identity = identity;
        }
示例#2
0
        /// <summary>
        /// Initializes a new instance of the Sentinel.OAuth.Models.Identity.SentinelPrincipal class.
        /// </summary>
        /// <exception cref="ArgumentNullException">
        /// Thrown when one or more required arguments are null.
        /// </exception>
        /// <param name="identity">The identity.</param>
        public SentinelPrincipal(ISentinelIdentity identity)
        {
            if (identity == null)
            {
                throw new ArgumentNullException(nameof(identity));
            }

            this.Identity = identity;
        }
        /// <summary>
        /// An ISentinelIdentity extension method that converts an identity to an identity response.
        /// </summary>
        /// <param name="identity">The identity.</param>
        /// <returns>An IdentityResponse.</returns>
        public static IdentityResponse ToIdentityResponse(this ISentinelIdentity identity)
        {
            var claims = new List <KeyValuePair <string, string> >();

            foreach (var claim in identity.Claims)
            {
                claims.Add(new KeyValuePair <string, string>(claim.Type, claim.Value));
            }

            return(new IdentityResponse(claims));
        }
        /// <summary>
        ///     An ISentinelIdentity extension method that converts an identity to the claims
        ///     identity.
        /// </summary>
        /// <param name="identity">The identity.</param>
        /// <returns>A ClaimsIdentity.</returns>
        public static ClaimsIdentity ToClaimsIdentity(this ISentinelIdentity identity)
        {
            var i = new ClaimsIdentity(identity.Claims.ToClaims(), identity.AuthenticationType);

            // Add name identifier claim if it doesnt exist
            if (!i.HasClaim(x => x.Type == ClaimTypes.NameIdentifier))
            {
                i.AddClaim(new Claim(ClaimTypes.NameIdentifier, i.Name));
            }

            return(i);
        }
        /// <summary>
        /// An ISentinelIdentity extension method that converts an identity to an identity response.
        /// </summary>
        /// <param name="identity">The identity.</param>
        /// <returns>An IdentityResponse.</returns>
        public static IdentityResponse AsIdentityResponse(this ISentinelIdentity identity)
        {
            var claims = new List <KeyValuePair <string, string> >();

            foreach (var claim in identity.Claims)
            {
                if (!string.IsNullOrEmpty(claim.Alias))
                {
                    claims.Add(new KeyValuePair <string, string>(claim.Alias, claim.Value));
                }
                else
                {
                    claims.Add(new KeyValuePair <string, string>(claim.Type, claim.Value));
                }
            }

            return(new IdentityResponse(claims));
        }
 /// <summary>
 ///     An ISentinelIdentity extension method that converts an identity to the claims
 ///     identity.
 /// </summary>
 /// <param name="identity">The identity.</param>
 /// <returns>A ClaimsIdentity.</returns>
 public static ClaimsIdentity AsClaimsIdentity(this ISentinelIdentity identity)
 {
     return(new ClaimsIdentity(identity.Claims.ToClaims(), identity.AuthenticationType));
 }