Ejemplo n.º 1
0
        public static async Task <ClaimsIdentity> GetIdentityFromExternalProvider(this IOwinContext context)
        {
            if (context == null)
            {
                throw new ArgumentNullException("context");
            }

            var id = await context.GetIdentityFromExternalSignIn();

            if (id != null)
            {
                // this is mapping from the external IdP's issuer to the name of the
                // katana middleware that's registered in startup
                var result = await context.GetAuthenticationFrom(Constants.ExternalAuthenticationType);

                if (!result.Properties.Dictionary.Keys.Contains(Constants.Authentication.KatanaAuthenticationType))
                {
                    throw new InvalidOperationException("Missing KatanaAuthenticationType");
                }

                var provider  = result.Properties.Dictionary[Constants.Authentication.KatanaAuthenticationType];
                var newClaims = id.Claims.Select(x => new Claim(x.Type, x.Value, x.ValueType, provider));
                id = new ClaimsIdentity(newClaims, id.AuthenticationType);
            }
            return(id);
        }
Ejemplo n.º 2
0
        static async Task <ClaimsIdentity> GetIdentityFrom(this IOwinContext context, string authenticationType)
        {
            var result = await context.GetAuthenticationFrom(authenticationType);

            if (result != null &&
                result.Identity != null &&
                result.Identity.IsAuthenticated)
            {
                return(result.Identity);
            }
            return(null);
        }
Ejemplo n.º 3
0
        internal static async Task <string> GetSignInIdFromExternalProvider(this IOwinContext context)
        {
            var result = await context.GetAuthenticationFrom(Constants.ExternalAuthenticationType);

            if (result != null)
            {
                string val;
                if (result.Properties.Dictionary.TryGetValue(Constants.Authentication.SigninId, out val))
                {
                    return(val);
                }
            }
            return(null);
        }
Ejemplo n.º 4
0
        public static async Task <ClaimsIdentity> GetIdentityFrom(this IOwinContext context, string authenticationType)
        {
            if (context == null)
            {
                throw new ArgumentNullException("context");
            }

            var result = await context.GetAuthenticationFrom(authenticationType);

            if (result != null &&
                result.Identity != null &&
                result.Identity.IsAuthenticated)
            {
                return(result.Identity);
            }
            return(null);
        }
        public static async Task <string> GetSignInIdFromExternalProvider(this IOwinContext context)
        {
            if (context == null)
            {
                throw new ArgumentNullException(nameof(context));
            }

            var result = await context.GetAuthenticationFrom(Constants.ExternalAuthenticationType);

            if (result != null)
            {
                string val;
                if (result.Properties.Dictionary.TryGetValue(Constants.Authentication.SigninId, out val))
                {
                    return(val);
                }
            }
            return(null);
        }