当前位置: 首页>>代码示例>>C#>>正文


C# IAuthSession.HasRole方法代码示例

本文整理汇总了C#中IAuthSession.HasRole方法的典型用法代码示例。如果您正苦于以下问题:C# IAuthSession.HasRole方法的具体用法?C# IAuthSession.HasRole怎么用?C# IAuthSession.HasRole使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在IAuthSession的用法示例。


在下文中一共展示了IAuthSession.HasRole方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: HasAllRoles

        public bool HasAllRoles(IAuthSession session, IAuthRepository authRepo)
        {
            if (session == null)
                return false;

            return this.RequiredRoles.All(x => session.HasRole(x, authRepo));
        }
开发者ID:AVee,项目名称:ServiceStack,代码行数:7,代码来源:RequiredRoleAttribute.cs

示例2: OnAuthenticated

        public override void OnAuthenticated(
            IServiceBase authService,
            IAuthSession session,
            IOAuthTokens tokens,
            Dictionary<string, string> authInfo)
        {
            base.OnAuthenticated(authService, session, tokens, authInfo);

            //Populate all matching fields from this session to your own custom User table
            var user = session.TranslateTo<User>();
            user.Id = int.Parse(session.UserAuthId);
            //user.GravatarImageUrl64 = !session.Email.IsNullOrEmpty() ? CreateGravatarUrl(session.Email, 64) : null;

            foreach (var authToken in session.ProviderOAuthAccess)
            {
                //    //if (authToken.Provider == FacebookAuthProvider.Name)
                //    //{
                //    //    user.FacebookName = authToken.DisplayName;
                //    //    user.FacebookFirstName = authToken.FirstName;
                //    //    user.FacebookLastName = authToken.LastName;
                //    //    user.FacebookEmail = authToken.Email;
                //    //}
                //    //else
                if (authToken.Provider == GoogleOpenIdOAuthProvider.Name)
                {
                    user.GoogleUserId = authToken.UserId;
                    user.GoogleFullName = authToken.FullName;
                    user.GoogleEmail = authToken.Email;
                    if (user.Email == null) user.Email = user.GoogleEmail;
                    if (user.UserName == null) user.UserName = user.GoogleUserId;
                }
                else if (authToken.Provider == YahooOpenIdOAuthProvider.Name)
                {
                    user.YahooUserId = authToken.UserId;
                    user.YahooFullName = authToken.FullName;
                    user.YahooEmail = authToken.Email;
                }
            }

            var adminUserNames = AppHost.AppConfig.AdminUserNames;

            if (AppHost.AppConfig.AdminUserNames.Contains(session.UserAuthName)
                && !session.HasRole(RoleNames.Admin))
            {
                using (var assignRoles = authService.ResolveService<AssignRolesService>())
                {
                    assignRoles.Post(new AssignRoles
                        {
                            UserName = session.UserAuthName,
                            Roles = { RoleNames.Admin }
                        });
                    //authService.TryResolve<IDbConnectionFactory>().Run(db => db.Save(user));
                }
            }

            //Resolve the DbFactory from the IOC and persist the user info
        }
开发者ID:robertdean,项目名称:RavenMDB2,代码行数:57,代码来源:CustomUserSession.cs

示例3: OnAuthenticated

        public override void OnAuthenticated(IServiceBase authService, IAuthSession session, IAuthTokens tokens, Dictionary<string, string> authInfo)
        {
            base.OnAuthenticated(authService, session, tokens, authInfo);

            //Populate all matching fields from this session to your own custom User table
            var user = session.ConvertTo<User>();
            user.Id = int.Parse(session.UserAuthId);
            user.GravatarImageUrl64 = !session.Email.IsNullOrEmpty()
                ? CreateGravatarUrl(session.Email, 64)
                : null;

            foreach (var authToken in session.ProviderOAuthAccess)
            {
                if (authToken.Provider == FacebookAuthProvider.Name)
                {
                    user.FacebookName = authToken.DisplayName;
                    user.FacebookFirstName = authToken.FirstName;
                    user.FacebookLastName = authToken.LastName;
                    user.FacebookEmail = authToken.Email;
                }
                else if (authToken.Provider == TwitterAuthProvider.Name)
                {
                    user.TwitterName = user.DisplayName = authToken.UserName;
                }
                else if (authToken.Provider == YahooOpenIdOAuthProvider.Name)
                {
                    user.YahooUserId = authToken.UserId;
                    user.YahooFullName = authToken.FullName;
                    user.YahooEmail = authToken.Email;
                }
            }

            var userAuthRepo = authService.TryResolve<IAuthRepository>();
            if (AppHost.AppConfig.AdminUserNames.Contains(session.UserAuthName)
                && !session.HasRole(RoleNames.Admin, userAuthRepo))
            {
                var userAuth = userAuthRepo.GetUserAuth(session, tokens);
                userAuthRepo.AssignRoles(userAuth, roles: new[] { RoleNames.Admin });
            }

            //Resolve the DbFactory from the IOC and persist the user info
            using (var db = authService.TryResolve<IDbConnectionFactory>().Open())
            {
                db.Save(user);
            }
        }
开发者ID:ServiceStackApps,项目名称:SocialBootstrapApi,代码行数:46,代码来源:CustomUserSession.cs

示例4: HasAllRoles

 public bool HasAllRoles(IAuthSession session)
 {
     return this.RequiredRoles
         .All(requiredRole => session != null
             && session.HasRole(requiredRole));
 }
开发者ID:qqqzhch,项目名称:ServiceStack,代码行数:6,代码来源:RequiredRoleAttribute.cs

示例5: IsAuthorized

        public bool IsAuthorized(Operation operation, IRequest req, IAuthSession session)
        {
            if (HostContext.HasValidAuthSecret(req))
                return true;

            if (operation.RequiresAuthentication && !session.IsAuthenticated)
                return false;

            var authRepo = HostContext.AppHost.GetAuthRepository(req);
            using (authRepo as IDisposable)
            {
                if (!operation.RequiredRoles.IsEmpty() && !operation.RequiredRoles.All(x => session.HasRole(x, authRepo)))
                    return false;

                if (!operation.RequiredPermissions.IsEmpty() && !operation.RequiredPermissions.All(x => session.HasPermission(x, authRepo)))
                    return false;

                if (!operation.RequiresAnyRole.IsEmpty() && !operation.RequiresAnyRole.Any(x => session.HasRole(x, authRepo)))
                    return false;

                if (!operation.RequiresAnyPermission.IsEmpty() && !operation.RequiresAnyPermission.Any(x => session.HasPermission(x, authRepo)))
                    return false;

                return true;
            }
        }
开发者ID:ServiceStack,项目名称:ServiceStack,代码行数:26,代码来源:ServiceMetadata.cs

示例6: HasAnyRoles

 public virtual bool HasAnyRoles(IAuthSession session)
 {
     return this.RequiredRoles
         .Any(requiredRole => session != null
             && session.HasRole(requiredRole));
 }
开发者ID:BilliamBrown,项目名称:ServiceStack,代码行数:6,代码来源:RequiresAnyRoleAttribute.cs

示例7: HasAnyRoles

 public virtual bool HasAnyRoles(IAuthSession session, IAuthRepository authRepo)
 {
     return this.RequiredRoles
         .Any(requiredRole => session != null
             && session.HasRole(requiredRole, authRepo));
 }
开发者ID:CLupica,项目名称:ServiceStack,代码行数:6,代码来源:RequiresAnyRoleAttribute.cs


注:本文中的IAuthSession.HasRole方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。