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


C# IAuthTokens类代码示例

本文整理汇总了C#中IAuthTokens的典型用法代码示例。如果您正苦于以下问题:C# IAuthTokens类的具体用法?C# IAuthTokens怎么用?C# IAuthTokens使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


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

示例1: LoadUserAuth

        public void LoadUserAuth(IAuthSession session, IAuthTokens tokens)
        {
            session.ThrowIfNull("session");

            var userAuth = GetUserAuth(session, tokens);
            LoadUserAuth(session, (UserAuth)userAuth);
        }
开发者ID:rudygt,项目名称:ServiceStack,代码行数:7,代码来源:NHibernateUserAuthRepository.cs

示例2: GetUserAuth

        public IUserAuth GetUserAuth(IAuthSession authSession, IAuthTokens tokens)
        {
            if (!string.IsNullOrEmpty(authSession.UserAuthId))
            {
                var userAuth = GetUserAuth(authSession.UserAuthId);
                if (userAuth != null) return userAuth;
            }

            if (!string.IsNullOrEmpty(authSession.UserAuthName))
            {
                var userAuth = GetUserAuthByUserName(authSession.UserAuthName);
                if (userAuth != null) return userAuth;
            }

            if (tokens == null || string.IsNullOrEmpty(tokens.Provider) || string.IsNullOrEmpty(tokens.UserId))
                return null;

            var oAuthProvider = Session.QueryOver<UserAuthDetails>()
                .Where(x => x.Provider == tokens.Provider)
                .And(x => x.UserId == tokens.UserId)
                .SingleOrDefault();

            if (oAuthProvider != null)
            {
                return Session.QueryOver<UserAuthPersistenceDto>()
                    .Where(x => x.Id == oAuthProvider.UserAuthId)
                    .SingleOrDefault();
            }

            return null;
        }
开发者ID:rikbosch,项目名称:ServiceStack,代码行数:31,代码来源:NHibernateUserAuthRepository.cs

示例3: SaveUserAuth

        /// <summary>
        /// Saves the Auth Tokens for this request. Called in OnAuthenticated(). 
        /// Overrideable, the default behaviour is to call IUserAuthRepository.CreateOrMergeAuthSession().
        /// </summary>
        protected virtual void SaveUserAuth(IServiceBase authService, IAuthSession session, IAuthRepository authRepo, IAuthTokens tokens)
        {
            if (authRepo == null) return;
            if (tokens != null)
            {
                session.UserAuthId = authRepo.CreateOrMergeAuthSession(session, tokens);
            }

            authRepo.LoadUserAuth(session, tokens);

            foreach (var oAuthToken in session.ProviderOAuthAccess)
            {
                var authProvider = AuthenticateService.GetAuthProvider(oAuthToken.Provider);
                if (authProvider == null) continue;
                var userAuthProvider = authProvider as OAuthProvider;
                if (userAuthProvider != null)
                {
                    userAuthProvider.LoadUserOAuthProvider(session, oAuthToken);
                }
            }

            authRepo.SaveUserAuth(session);

            var httpRes = authService.Request.Response as IHttpResponse;
            if (httpRes != null)
            {
                httpRes.Cookies.AddPermanentCookie(HttpHeaders.XUserAuthId, session.UserAuthId);
            }
            OnSaveUserAuth(authService, session);
        }
开发者ID:JackFong,项目名称:ServiceStack,代码行数:34,代码来源:AuthProvider.cs

示例4: GetUserAuth

        public IUserAuth GetUserAuth(IAuthSession authSession, IAuthTokens tokens)
        {
            //if (!authSession.UserAuthId.IsNullOrEmpty())
            //{
            //    var userAuth = GetUserAuth(authSession.UserAuthId);
            //    if (userAuth != null)
            //    {
            //        return userAuth;
            //    }
            //}
            if (!authSession.UserAuthName.IsNullOrEmpty())
            {
                var userAuth = GetUserAuthByUserName(authSession.UserAuthName);
                if (userAuth != null)
                {
                    return userAuth;
                }
            }

            if (tokens == null || tokens.Provider.IsNullOrEmpty() || tokens.UserId.IsNullOrEmpty())
            {
                return null;
            }

            return null;
        }
开发者ID:Filimindji,项目名称:YAQAAP,代码行数:26,代码来源:AzureAuthProvider.cs

示例5: AddProfileUrl

        public virtual void AddProfileUrl(IAuthTokens tokens, Dictionary<string, string> authInfo)
        {
            if (tokens == null || authInfo == null)
                return;
            
            var items = tokens.Items ?? (tokens.Items = new Dictionary<string, string>());
            if (items.ContainsKey(ProfileUrlKey))
                return;

            try
            {
                //Provide Fallback to retrieve avatar urls in-case built-in access fails
                if (tokens.Provider == FacebookAuthProvider.Name)
                {
                    items[ProfileUrlKey] = GetRedirectUrlIfAny(
                        $"http://avatars.io/facebook/{tokens.UserName}?size=medium");
                }
                else if (tokens.Provider == TwitterAuthProvider.Name)
                {
                    items[ProfileUrlKey] = GetRedirectUrlIfAny(
                        $"http://avatars.io/twitter/{tokens.UserName}?size=medium");
                }

                if (!items.ContainsKey(ProfileUrlKey) && !tokens.Email.IsNullOrEmpty())
                    items[ProfileUrlKey] = tokens.Email.ToGravatarUrl(size: 64);
            }
            catch (Exception ex)
            {
                Log.Error("Error AddProfileUrl to: {0}>{1}".Fmt(tokens.Provider, tokens.UserName), ex);
            }
        }
开发者ID:AVee,项目名称:ServiceStack,代码行数:31,代码来源:AuthMetadataProvider.cs

示例6: AddAuthToken

        public static void AddAuthToken(this IAuthSession session, IAuthTokens tokens)
        {
            if (session.ProviderOAuthAccess == null)
                session.ProviderOAuthAccess = new List<IAuthTokens>();

            session.ProviderOAuthAccess.Add(tokens);
        }
开发者ID:CLupica,项目名称:ServiceStack,代码行数:7,代码来源:AuthUserSession.cs

示例7: GetUserAuth

        public IUserAuth GetUserAuth(IAuthSession authSession, IAuthTokens tokens)
        {
            if (!string.IsNullOrEmpty(authSession.UserAuthId))
            {
                var userAuth = GetUserAuth(authSession.UserAuthId);
                if (userAuth != null) return userAuth;
            }

            if (!string.IsNullOrEmpty(authSession.UserAuthName))
            {
                var userAuth = GetUserAuthByUserName(authSession.UserAuthName);
                if (userAuth != null) return userAuth;
            }

            if (tokens == null || string.IsNullOrEmpty(tokens.Provider) || string.IsNullOrEmpty(tokens.UserId))
                return null;

            var nhSession = GetCurrentSessionFn(sessionFactory);
            var oAuthProvider = nhSession.QueryOver<UserAuthDetailsNHibernate>()
                .Where(x => x.Provider == tokens.Provider)
                .And(x => x.UserId == tokens.UserId)
                .SingleOrDefault();

            if (oAuthProvider != null)
            {
                return nhSession.QueryOver<UserAuthNHibernate>()
                    .Where(x => x.Id == oAuthProvider.UserAuthId)
                    .SingleOrDefault();
            }

            return null;
        }
开发者ID:rudygt,项目名称:ServiceStack,代码行数:32,代码来源:NHibernateUserAuthRepository.cs

示例8: LoadUserAuth

        public void LoadUserAuth(IAuthSession session, IAuthTokens tokens)
        {
            if (session == null)
                throw new ArgumentNullException(nameof(session));

            var userAuth = GetUserAuth(session, tokens);
            LoadUserAuth(session, (UserAuth)userAuth);
        }
开发者ID:AVee,项目名称:ServiceStack,代码行数:8,代码来源:NHibernateUserAuthRepository.cs

示例9: OnAuthenticated

 /// <summary>
 /// The on-authenticated event handler.
 /// </summary>
 /// <param name="authService">The authentication service.</param>
 /// <param name="session">The authentication session.</param>
 /// <param name="tokens">The authentication tokens.</param>
 /// <param name="authInfo">The authentication information.</param>
 public override void OnAuthenticated(
     IServiceBase authService,
     IAuthSession session,
     IAuthTokens tokens,
     Dictionary<string, string> authInfo)
 {
     base.OnAuthenticated(authService, session, tokens, authInfo);
 }
开发者ID:hhandoko,项目名称:sslakka_archive,代码行数:15,代码来源:UserSession.cs

示例10: OnAuthenticated

        /// <summary>
        /// Método que se ejecuta cuando se ha autenticado con éxito
        /// </summary>
        /// <param name="authService">Servicio que solicita la autenticación</param>
        /// <param name="session">Información de sesión</param>
        /// <param name="tokens">Tokets</param>
        /// <param name="authInfo">Información de autenticación</param>
        /// <returns></returns>
        public override IHttpResult OnAuthenticated(IServiceBase authService, IAuthSession session, IAuthTokens tokens, Dictionary<string, string> authInfo)
        {
            session.FirstName = _fullName;

            authService.SaveSession(session);

            return null;
        }
开发者ID:jdmartinez,项目名称:Northwind,代码行数:16,代码来源:NorthwindAuthProvider.cs

示例11: IsAuthorized

        public override bool IsAuthorized(IAuthSession session, IAuthTokens tokens, Authenticate request = null)
        {
            if (request != null)
            {
                if (!LoginMatchesSession(session, request.UserName)) return false;
            }

            return tokens != null && !string.IsNullOrEmpty(tokens.AccessTokenSecret);
        }
开发者ID:GDBSD,项目名称:ServiceStack,代码行数:9,代码来源:OAuthProvider.cs

示例12: LoadUserOAuthProvider

 public override void LoadUserOAuthProvider(IAuthSession authSession, IAuthTokens tokens)
 {
     var userSession = authSession as AuthUserSession;
     if (userSession == null) return;
     
     userSession.TwitterUserId = tokens.UserId ?? userSession.TwitterUserId;
     userSession.TwitterScreenName = tokens.UserName ?? userSession.TwitterScreenName;
     userSession.DisplayName = tokens.DisplayName ?? userSession.DisplayName;
 }
开发者ID:AVee,项目名称:ServiceStack,代码行数:9,代码来源:TwitterAuthProvider.cs

示例13: IsAuthorized

        public override bool IsAuthorized(IAuthSession session, IAuthTokens tokens, Authenticate request = null)
        {
            if (request != null) {
                if (!LoginMatchesSession(session, request.UserName)) {
                    return false;
                }
            }

            return !session.UserAuthName.IsNullOrEmpty();
        }
开发者ID:jango2015,项目名称:ServiceStack,代码行数:10,代码来源:DigestAuthProvider.cs

示例14: 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 == GoogleOpenIdOAuthProvider.Name)
                {
                    user.GoogleUserId = authToken.UserId;
                    user.GoogleFullName = authToken.FullName;
                    user.GoogleEmail = authToken.Email;
                }
                else if (authToken.Provider == YahooOpenIdOAuthProvider.Name)
                {
                    user.YahooUserId = authToken.UserId;
                    user.YahooFullName = authToken.FullName;
                    user.YahooEmail = authToken.Email;
                }
            }

            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 }
                    });
                }
            }

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

示例15: IsAuthorized

        public override bool IsAuthorized(IAuthSession session, IAuthTokens tokens, Authenticate request = null)
        {
            if (request != null)
            {
                //if (!LoginMatchesSession(session, request.UserName))
                //{
                //	return false;
                //}
                throw new NotImplementedException();
            }

            return session != null && session.IsAuthenticated && !session.UserAuthName.IsNullOrEmpty();
        }
开发者ID:cri-at-work,项目名称:SS-AuthProvider,代码行数:13,代码来源:UnityServiceAuthProvider.cs


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