protected override void RequestStartup(TinyIoCContainer container, IPipelines pipelines, NancyContext context)
 {
     base.RequestStartup(container, pipelines, context);
     var owinEnvironment = context.GetOwinEnvironment();
     var user = owinEnvironment["server.User"] as ClaimsPrincipal;
     context.CurrentUser = new DemoUserIdentity()
     {
         UserName = user.Identity.Name,
         Claims = user.Claims.Select(x => x.Value)
     };
 }
Пример #2
0
        protected override void RequestStartup(IContainer container, IPipelines pipelines, NancyContext context)
        {
            base.RequestStartup(container, pipelines, context);
            var owinEnvironment = context.GetOwinEnvironment();
            if (!owinEnvironment.ContainsKey("server.User")) return;

            var user = owinEnvironment["server.User"] as ClaimsPrincipal;
            if (user != null && user.Identity.IsAuthenticated)
            {
                context.CurrentUser =
                    new CustomUserIdentity(Guid.Parse(user.Claims.Single(x => x.Type == ClaimTypes.NameIdentifier).Value),
                        user.Identity.Name, user.Claims.Select(x => x.Value));
            }
        }
 protected override void RequestStartup(TinyIoCContainer container, IPipelines pipelines, NancyContext context)
 {
     base.RequestStartup(container, pipelines, context);
     var owinEnvironment = context.GetOwinEnvironment();
     var user = owinEnvironment["server.User"] as ClaimsPrincipal;
     if (user != null)
     {
         context.CurrentUser = new DemoUserIdentity()
         {
             UserName = user.Identity.Name,
             Claims = user.Claims.Where(x => x.Type == "http://schemas.microsoft.com/ws/2008/06/identity/claims/role").Select(x => x.Value)
         };
     }
 }
Пример #4
0
        protected override void RequestStartup(TinyIoCContainer container, IPipelines pipelines, NancyContext context)
        {
            base.RequestStartup(container, pipelines, context);

            var owinEnvironment = context.GetOwinEnvironment();

            var principal = owinEnvironment?["server.User"] as ClaimsPrincipal;

            if (principal == null) return;

            var userName = principal.Identity.Name;
            var claims = principal.Claims.Where(
                o => o.Type == ClaimTypes.Role)
                .Select(o => o.Value);
            context.CurrentUser = new ValidatedUser(userName, claims);
        }
Пример #5
0
        protected override void RequestStartup(TinyIoCContainer container, IPipelines pipelines, NancyContext context)
        {
            base.RequestStartup(container, pipelines, context);
            StaticConfiguration.DisableErrorTraces = false;
            var owinEnvironment = context.GetOwinEnvironment();
            var user = owinEnvironment["server.User"] as ClaimsPrincipal;
            if (user != null)
            {
                context.CurrentUser = new DemoUserIdentity
                {
                    UserName = user.Identity.Name,
                    Claims = user.Claims.Where(x => x.Type == "http://schemas.microsoft.com/ws/2008/06/identity/claims/role").Select(x => x.Value)
                };
            }

            pipelines.OnError.AddItemToEndOfPipeline((z, a) =>
            {
                return null;
            });
        }
Пример #6
0
        private static Response FlowPrincipal(NancyContext context)
        {
            var env = context.GetOwinEnvironment();
            if (env == null) 
                return null;

            var principal = env.Get<IPrincipal>("server.User") as ClaimsPrincipal;
            if (principal != null)
                context.CurrentUser = new TheBenchUser(new TheBenchPrincipal(principal));

            return null;
        }