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


C# IServiceBase.SaveSession方法代码示例

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


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

示例1: Authenticate

        public override object Authenticate(IServiceBase authService, IAuthSession session, Authenticate request)
        {
            var tokens = Init(authService, ref session, request);
            var httpRequest = authService.Request;

            var error = httpRequest.QueryString["error_reason"]
                ?? httpRequest.QueryString["error"]
                ?? httpRequest.QueryString["error_code"]
                ?? httpRequest.QueryString["error_description"];

            var hasError = !error.IsNullOrEmpty();
            if (hasError)
            {
                Log.Error("Facebook error callback. {0}".Fmt(httpRequest.QueryString));
                return authService.Redirect(session.ReferrerUrl);
            }             
        
            var code = httpRequest.QueryString["code"];
            var isPreAuthCallback = !code.IsNullOrEmpty();
            if (!isPreAuthCallback)
            {
                var preAuthUrl = PreAuthUrl + "?client_id={0}&redirect_uri={1}&scope={2}"
                    .Fmt(AppId, this.CallbackUrl.UrlEncode(), string.Join(",", Permissions));

                authService.SaveSession(session, SessionExpiry);
                return authService.Redirect(preAuthUrl);
            }

            var accessTokenUrl = this.AccessTokenUrl + "?client_id={0}&redirect_uri={1}&client_secret={2}&code={3}"
                .Fmt(AppId, this.CallbackUrl.UrlEncode(), AppSecret, code);

            try
            {
                var contents = accessTokenUrl.GetStringFromUrl();
                var authInfo = HttpUtility.ParseQueryString(contents);
                tokens.AccessTokenSecret = authInfo["access_token"];
                session.IsAuthenticated = true;
                authService.SaveSession(session, SessionExpiry);
                OnAuthenticated(authService, session, tokens, authInfo.ToDictionary());

                //Haz access!
                return authService.Redirect(session.ReferrerUrl.AddHashParam("s", "1"));
            }
            catch (WebException we)
            {
                var statusCode = ((HttpWebResponse)we.Response).StatusCode;
                if (statusCode == HttpStatusCode.BadRequest)
                {
                    return authService.Redirect(session.ReferrerUrl.AddHashParam("f", "AccessTokenFailed"));
                }
            }

            //Shouldn't get here
            return authService.Redirect(session.ReferrerUrl.AddHashParam("f", "Unknown"));
        }
开发者ID:GDBSD,项目名称:ServiceStack,代码行数:55,代码来源:FacebookAuthProvider.cs

示例2: OnAuthenticated

 public override void OnAuthenticated(IServiceBase authService,
     IAuthSession session, IOAuthTokens tokens, Dictionary<string, string> authInfo)
 {
     session.ReferrerUrl = "".MapHostAbsolutePath();
     session.IsAuthenticated = true;
     authService.SaveSession(session, new TimeSpan(7, 0, 0, 0));
 }
开发者ID:TripThru,项目名称:Gateway,代码行数:7,代码来源:1396661660$TripThruPartnerGatewayHost.cs

示例3: OnAuthenticated

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

            //Important: You need to save the session!
            authService.SaveSession(session, SessionExpiry);
        }
开发者ID:bholmes,项目名称:XamarinEvolve2013Project,代码行数:7,代码来源:CustomCredentialsAuthProvider.cs

示例4: OnAuthenticated

 public override void OnAuthenticated(IServiceBase authService,
     IAuthSession session, IOAuthTokens tokens, Dictionary<string, string> authInfo)
 {
     session.ReferrerUrl = "/TripThru.TripThruGateway/";
     session.IsAuthenticated = true;
     authService.SaveSession(session, new TimeSpan(7, 0, 0, 0));
 }
开发者ID:TripThru,项目名称:Gateway,代码行数:7,代码来源:1396661635$TripThruGatewayHost.cs

示例5: 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

示例6: OnAuthenticated

        public override void OnAuthenticated(IServiceBase authService, IAuthSession session, IOAuthTokens tokens, Dictionary<string, string> authInfo)
        {
            //Fill the IAuthSession with data which you want to retrieve in the app eg:
            //session.FirstName = "some_firstname_from_db";
            //...

            //Important: You need to save the session!
            authService.SaveSession(session, SessionExpiry);
        }
开发者ID:writeameer,项目名称:ServiceStackRazor,代码行数:9,代码来源:CustomCredentialsAuthProvider.cs

示例7: OnAuthenticated

            public override void OnAuthenticated(IServiceBase authService, IAuthSession session, IOAuthTokens tokens,
                    Dictionary<string, string> authInfo)
            {
                //Fill IAuthSession with data you want to retrieve in the app eg:
                    //Load the Session Object
                    session.FirstName = "some_firstname_from_db";
                    session.LastName = "some_last_name_from_db";

                    authService.SaveSession(session, SessionExpiry);
            }
开发者ID:rafareyes7,项目名称:UnifyWS,代码行数:10,代码来源:AppHost.cs

示例8: OnAuthenticated

        public override void OnAuthenticated(IServiceBase authService, IAuthSession session, IOAuthTokens tokens, Dictionary<string, string> authInfo)
        {
            // Note:
            // `session.UserAuthName` is already set to the user's user name.
            // we use `session.UserName` for the user's secret unique id.

            var usersRepo = authService.TryResolve<IUsersRepository>();
            var user = usersRepo.GetOrCreateUser(session.UserAuthName);
            session.UserName = user.UserId;
            authService.SaveSession(session);
        }
开发者ID:eteeselink,项目名称:sioux_tech_radar,代码行数:11,代码来源:SiouxAuthProvider.cs

示例9: OnAuthenticated

 public override void OnAuthenticated(IServiceBase authService,
     IAuthSession session, IOAuthTokens tokens, Dictionary<string, string> authInfo)
 {
     session.ReferrerUrl = referrerUrl;
     session.IsAuthenticated = true;
     var user = StorageManager.GetPartnerAccountByUsername(session.UserAuthName);
     session.UserName = user.UserName;
     session.Id = user.ClientId;
     session.Roles = new List<string>() {user.Role.ToString()};
     authService.SaveSession(session, new TimeSpan(7, 0, 0, 0));
 }
开发者ID:TripThru,项目名称:Gateway,代码行数:11,代码来源:TripThruGatewayHost.cs

示例10: OnAuthenticated

        public override void OnAuthenticated(IServiceBase authService, IAuthSession session, IOAuthTokens tokens, Dictionary<string, string> authInfo) {
            //Fill the IAuthSession with data which you want to retrieve in the app eg:
            session.FirstName = "garrett";
            session.Roles = new List<string>();
            session.Roles.Add("users");
            session.Roles.Add("admins");
            
            //...

            //Important: You need to save the session!
            authService.SaveSession(session, SessionExpiry);
        }
开发者ID:roomaroo,项目名称:coapp.powershell,代码行数:12,代码来源:CustomCredentialsAuthProvider.cs

示例11: Authenticate

        public override object Authenticate(IServiceBase authService, IAuthSession session, Auth request)
        {
            var tokens = Init(authService, ref session, request);

            //TODO: For now, later check for incoming URL to see from where it comes and decide...
            bool isAuthenticated = this.IsAuthorizedBySts(session, null, request);

            if (!isAuthenticated)
            {
               authService.SaveSession(session, SessionExpiry);
               return  AuthenticateWithSTS(authService, session, request);
            }

            return CompleteAuthentication(authService, session, request, tokens);
        }
开发者ID:rasikas,项目名称:SocialBootstrapApi,代码行数:15,代码来源:StsAuthProvider.cs

示例12: OnAuthenticated

        public override ServiceStack.Web.IHttpResult OnAuthenticated(IServiceBase authService, IAuthSession session,
            IAuthTokens tokens, Dictionary<string, string> authInfo)
        {
            //Fill IAuthSession with data you want to retrieve in the app eg:

            session.FirstName = "FirstName";
            session.LastName = "LastName";
            session.DisplayName = "Display Name";
            session.Email = "[email protected]";
            session.IsAuthenticated = true;
            session.UserName = "Username";
            session.UserAuthId = "001";
            //...

            //Important: You need to save the session!
            authService.SaveSession(session, SessionExpiry);
            return default(ServiceStack.Web.IHttpResult);
        }
开发者ID:MBrekhof,项目名称:ssforms,代码行数:18,代码来源:CustomAuthentication.cs

示例13: Authenticate

        /// <summary>
        /// The entry point for all AuthProvider providers. Runs inside the AuthService so exceptions are treated normally.
        /// Overridable so you can provide your own Auth implementation.
        /// </summary>
        /// <param name="authService"></param>
        /// <param name="session"></param>
        /// <param name="request"></param>
        /// <returns></returns>
        public override object Authenticate(IServiceBase authService, IAuthSession session, Authenticate request)
        {
            var tokens = Init(authService, ref session, request);

            //Default OAuth logic based on Twitter's OAuth workflow
            if (!tokens.RequestToken.IsNullOrEmpty() && !request.oauth_token.IsNullOrEmpty())
            {
                OAuthUtils.RequestToken = tokens.RequestToken;
                OAuthUtils.RequestTokenSecret = tokens.RequestTokenSecret;
                OAuthUtils.AuthorizationToken = request.oauth_token;
                OAuthUtils.AuthorizationVerifier = request.oauth_verifier;

                if (OAuthUtils.AcquireAccessToken())
                {
                    tokens.AccessToken = OAuthUtils.AccessToken;
                    tokens.AccessTokenSecret = OAuthUtils.AccessTokenSecret;
                    session.IsAuthenticated = true;
                    OnAuthenticated(authService, session, tokens, OAuthUtils.AuthInfo);
                    authService.SaveSession(session, SessionExpiry);

                    //Haz access!
                    return authService.Redirect(session.ReferrerUrl.AddHashParam("s", "1"));
                }

                //No Joy :(
                tokens.RequestToken = null;
                tokens.RequestTokenSecret = null;
                authService.SaveSession(session, SessionExpiry);
                return authService.Redirect(session.ReferrerUrl.AddHashParam("f", "AccessTokenFailed"));
            }
            if (OAuthUtils.AcquireRequestToken())
            {
                tokens.RequestToken = OAuthUtils.RequestToken;
                tokens.RequestTokenSecret = OAuthUtils.RequestTokenSecret;
                authService.SaveSession(session, SessionExpiry);

                //Redirect to OAuth provider to approve access
                return authService.Redirect(this.AuthorizeUrl
                    .AddQueryParam("oauth_token", tokens.RequestToken)
                    .AddQueryParam("oauth_callback", session.ReferrerUrl));
            }

            return authService.Redirect(session.ReferrerUrl.AddHashParam("f", "RequestTokenFailed"));
        }
开发者ID:GDBSD,项目名称:ServiceStack,代码行数:52,代码来源:OAuthProvider.cs

示例14: Authenticate

        public override object Authenticate(IServiceBase service, OAuth request, IOAuthSession session, IOAuthTokens tokens, OAuthAuthorizer oAuth)
        {
            var code = service.RequestContext.Get<IHttpRequest>().QueryString["code"];
            var isPreAuthCallback = !code.IsNullOrEmpty();
            if (!isPreAuthCallback)
            {
                var preAuthUrl = PreAuthUrl + "?client_id={0}&redirect_uri={1}&scope={2}"
                    .Fmt(AppId, this.CallbackUrl.UrlEncode(), string.Join(",", Permissions));
                return service.Redirect(preAuthUrl);
            }

            var accessTokenUrl = this.AccessTokenUrl + "?client_id={0}&redirect_uri={1}&client_secret={2}&code={3}"
                .Fmt(AppId, this.CallbackUrl.UrlEncode(), AppSecret, code);

            try
            {
                var contents = accessTokenUrl.DownloadUrl();
                var authInfo = HttpUtility.ParseQueryString(contents);
                tokens.AccessTokenSecret = authInfo["access_token"];
                service.SaveSession(session);
                session.OnAuthenticated(service, tokens, authInfo.ToDictionary());

                //Haz access!
                return service.Redirect(session.ReferrerUrl.AddQueryParam("s", "1"));
            }
            catch (WebException we)
            {
                var statusCode = ((HttpWebResponse)we.Response).StatusCode;
                if (statusCode == HttpStatusCode.BadRequest)
                {
                    return service.Redirect(session.ReferrerUrl.AddQueryParam("f", "AccessTokenFailed"));
                }
            }

            //Shouldn't get here
            return service.Redirect(session.ReferrerUrl.AddQueryParam("f", "Unknown"));
        }
开发者ID:benaston,项目名称:ServiceStack,代码行数:37,代码来源:OAuthConfig.cs

示例15: ValidateAccount

        protected virtual IHttpResult ValidateAccount(IServiceBase authService, IAuthRepository authRepo, IAuthSession session, IAuthTokens tokens)
        {
            var userAuth = authRepo.GetUserAuth(session, tokens);
            var isLocked = userAuth != null && userAuth.LockedDate != null;

            if (isLocked)
            {
                session.IsAuthenticated = false;
                authService.SaveSession(session, SessionExpiry);
                return authService.Redirect(session.ReferrerUrl.AddHashParam("f", "AccountLocked"));
            }

            return null;
        }
开发者ID:Krave-n,项目名称:ServiceStack,代码行数:14,代码来源:AuthProvider.cs


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