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


C# IServiceBase类代码示例

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


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

示例1: TryAuthenticate

        public override bool TryAuthenticate(IServiceBase authService, string userName, string password)
        {
            var authRepo = authService.TryResolve<IAuthRepository>().AsUserAuthRepository(authService.GetResolver());

            var session = authService.GetSession();
            IUserAuth userAuth;
            if (authRepo.TryAuthenticate(userName, password, out userAuth))
            {
                if (IsAccountLocked(authRepo, userAuth))
                    return false;
                // throw new AuthenticationException("This account has been locked");

                var holdSessionId = session.Id;
                session.PopulateWith(userAuth); //overwrites session.Id
                session.Id = holdSessionId;
                session.IsAuthenticated = true;
                session.UserAuthId = userAuth.Id.ToString(CultureInfo.InvariantCulture);
                session.ProviderOAuthAccess = authRepo.GetUserAuthDetails(session.UserAuthId)
                    .ConvertAll(x => (IAuthTokens)x);

                return true;
            }

            return false;
        }
开发者ID:aaronzoe,项目名称:Klkl,代码行数:25,代码来源:CustomCredentialsAuthProvider.cs

示例2: Authenticate

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


            string error = httpRequest.QueryString["error"];

            bool hasError = !error.IsNullOrEmpty();
            if (hasError)
            {
                Log.Error($"Odnoklassniki error callback. {httpRequest.QueryString}");
                return authService.Redirect(FailedRedirectUrlFilter(this, session.ReferrerUrl.SetParam("f", error)));
            }

            string code = httpRequest.QueryString["code"];
            bool isPreAuthCallback = !code.IsNullOrEmpty();
            if (!isPreAuthCallback)
            {
                string preAuthUrl = $"{PreAuthUrl}?client_id={ApplicationId}&redirect_uri={CallbackUrl.UrlEncode()}&response_type=code&layout=m";

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

            try
            {
                string payload = $"client_id={ApplicationId}&client_secret={SecretKey}&code={code}&redirect_uri={CallbackUrl.UrlEncode()}&grant_type=authorization_code";

                string contents = AccessTokenUrlFilter(this, AccessTokenUrl).PostToUrl(payload, "*/*", RequestFilter);

                var authInfo = JsonObject.Parse(contents);

                //ok.ru does not throw exception, but returns error property in JSON response
                string accessTokenError = authInfo.Get("error");

                if (!accessTokenError.IsNullOrEmpty())
                {
                    Log.Error($"Odnoklassniki access_token error callback. {authInfo}");
                    return authService.Redirect(session.ReferrerUrl.SetParam("f", "AccessTokenFailed"));
                }
                tokens.AccessTokenSecret = authInfo.Get("access_token");
                tokens.UserId = authInfo.Get("user_id");

                session.IsAuthenticated = true;

                return OnAuthenticated(authService, session, tokens, authInfo.ToDictionary())
                    ?? authService.Redirect(SuccessRedirectUrlFilter(this, session.ReferrerUrl.SetParam("s", "1")));
            }
            catch (WebException webException)
            {
                //just in case it starts throwing exceptions 
                HttpStatusCode statusCode = ((HttpWebResponse)webException.Response).StatusCode;
                if (statusCode == HttpStatusCode.BadRequest)
                {
                    return authService.Redirect(FailedRedirectUrlFilter(this, session.ReferrerUrl.SetParam("f", "AccessTokenFailed")));
                }
            }
            return authService.Redirect(FailedRedirectUrlFilter(this, session.ReferrerUrl.SetParam("f", "Unknown")));
        }
开发者ID:AVee,项目名称:ServiceStack,代码行数:60,代码来源:OdnoklassnikiAuthProvider.cs

示例3: Init

        protected IAuthTokens Init(IServiceBase authService, ref IAuthSession session, Authenticate request)
        {
            Logger.Debug("SamlAuthProvider::Init:ENTER");
            if (this.CallbackUrl.IsNullOrEmpty())
            {
                this.CallbackUrl = authService.Request.AbsoluteUri;
                Logger.Debug("CallbackUrl was null, setting to: {0}".Fmt(this.CallbackUrl));
            }

            if (session.ReferrerUrl.IsNullOrEmpty() && authService.Request != null && authService.Request.Verb == "POST")
            {
                session.ReferrerUrl = this.IdpInitiatedRedirect;
            }
            else {
                session.ReferrerUrl = GetReferrerUrl(authService, session, request);
            }
            Logger.Debug("Session ReferrerUrl Set to: {0}".Fmt(session.ReferrerUrl));

            var tokens = session.ProviderOAuthAccess.FirstOrDefault(x => x.Provider == this.Provider);
            if (tokens == null)
            {
                Logger.Debug("Tokens were null, initializing");
                session.ProviderOAuthAccess.Add(tokens = new AuthTokens { Provider = this.Provider });                
            }
            Logger.Debug("Tokens contains");
            Logger.Debug(tokens.ToJson());
            Logger.Debug("SamlAuthProvider::Init:RETURN");
            return tokens;
        }
开发者ID:americansystems,项目名称:servicestack-auth-saml,代码行数:29,代码来源:SamlAuthProvider.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: Logout

        /// <summary>
        /// Remove the Users Session
        /// </summary>
        /// <param name="service"></param>
        /// <param name="request"></param>
        /// <returns></returns>
        public virtual object Logout(IServiceBase service, Authenticate request)
        {
            var feature = HostContext.GetPlugin<AuthFeature>();

            var session = service.GetSession();
            var referrerUrl = (request != null ? request.Continue : null)
                ?? (feature.HtmlLogoutRedirect != null ? service.Request.ResolveAbsoluteUrl(feature.HtmlLogoutRedirect) : null)
                ?? session.ReferrerUrl
                ?? service.Request.GetHeader("Referer")
                ?? this.CallbackUrl;

            session.OnLogout(service);
            AuthEvents.OnLogout(service.Request, session, service);

            service.RemoveSession();

            if (feature != null && feature.DeleteSessionCookiesOnLogout)
            {
                service.Request.Response.DeleteSessionCookies();
            }

            if (service.Request.ResponseContentType == MimeTypes.Html && !string.IsNullOrEmpty(referrerUrl))
                return service.Redirect(LogoutUrlFilter(this, referrerUrl.SetParam("s", "-1")));

            return new AuthenticateResponse();
        }
开发者ID:AndreGleichner,项目名称:ServiceStack,代码行数:32,代码来源:AuthProvider.cs

示例6: TryAuthenticate

        public virtual bool TryAuthenticate(IServiceBase authService, string userName, string password)
        {
            var authRepo = HostContext.AppHost.GetAuthRepository(authService.Request);
            using (authRepo as IDisposable)
            {
                var session = authService.GetSession();
                var digestInfo = authService.Request.GetDigestAuth();
                IUserAuth userAuth;
                if (authRepo.TryAuthenticate(digestInfo, PrivateKey, NonceTimeOut, session.Sequence, out userAuth))
                {

                    var holdSessionId = session.Id;
                    session.PopulateWith(userAuth); //overwrites session.Id
                    session.Id = holdSessionId;
                    session.IsAuthenticated = true;
                    session.Sequence = digestInfo["nc"];
                    session.UserAuthId = userAuth.Id.ToString(CultureInfo.InvariantCulture);
                    session.ProviderOAuthAccess = authRepo.GetUserAuthDetails(session.UserAuthId)
                        .ConvertAll(x => (IAuthTokens)x);

                    return true;
                }
                return false;
            }
        }
开发者ID:AVee,项目名称:ServiceStack,代码行数:25,代码来源:DigestAuthProvider.cs

示例7: 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, IUserAuthRepository authRepo, IOAuthTokens 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 = AuthService.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.RequestContext.Get<IHttpResponse>();
            if (httpRes != null)
            {
                httpRes.Cookies.AddPermanentCookie(HttpHeaders.XUserAuthId, session.UserAuthId);
            }
            OnSaveUserAuth(authService, session);
        }
开发者ID:yeurch,项目名称:ServiceStack,代码行数:34,代码来源:AuthProvider.cs

示例8: Authenticate

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


            string error = httpRequest.QueryString["error"]
                           ?? httpRequest.QueryString["error_uri"]
                           ?? httpRequest.QueryString["error_description"];

            bool hasError = !error.IsNullOrEmpty();
            if (hasError)
            {
                Log.Error($"Yandex error callback. {httpRequest.QueryString}");
                return authService.Redirect(FailedRedirectUrlFilter(this, session.ReferrerUrl.SetParam("f", error)));
            }

            string code = httpRequest.QueryString["code"];
            bool isPreAuthCallback = !code.IsNullOrEmpty();
            if (!isPreAuthCallback)
            {
                string preAuthUrl = $"{PreAuthUrl}?response_type=code&client_id={ApplicationId}&redirect_uri={CallbackUrl.UrlEncode()}&display=popup&state={Guid.NewGuid().ToString("N")}";
                this.SaveSession(authService, session, SessionExpiry);
                return authService.Redirect(PreAuthUrlFilter(this, preAuthUrl));
            }

            try
            {
                string payload = $"grant_type=authorization_code&code={code}&client_id={ApplicationId}&client_secret={ApplicationPassword}";
                string contents = AccessTokenUrl.PostStringToUrl(payload);

                var authInfo = JsonObject.Parse(contents);

                //Yandex does not throw exception, but returns error property in JSON response
                // http://api.yandex.ru/oauth/doc/dg/reference/obtain-access-token.xml
                string accessTokenError = authInfo.Get("error");

                if (!accessTokenError.IsNullOrEmpty())
                {
                    Log.Error($"Yandex access_token error callback. {authInfo}");
                    return authService.Redirect(session.ReferrerUrl.SetParam("f", "AccessTokenFailed"));
                }
                tokens.AccessTokenSecret = authInfo.Get("access_token");

                session.IsAuthenticated = true;

                return OnAuthenticated(authService, session, tokens, authInfo.ToDictionary())
                    ?? authService.Redirect(SuccessRedirectUrlFilter(this, session.ReferrerUrl.SetParam("s", "1")));
            }
            catch (WebException webException)
            {
                //just in case Yandex will start throwing exceptions 
                var statusCode = ((HttpWebResponse)webException.Response).StatusCode;
                if (statusCode == HttpStatusCode.BadRequest)
                {
                    return authService.Redirect(FailedRedirectUrlFilter(this, session.ReferrerUrl.SetParam("f", "AccessTokenFailed")));
                }
            }
            return authService.Redirect(FailedRedirectUrlFilter(this, session.ReferrerUrl.SetParam("f", "Unknown")));
        }
开发者ID:AVee,项目名称:ServiceStack,代码行数:60,代码来源:YandexAuthProvider.cs

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

示例10: Authenticate

        public override object Authenticate(IServiceBase authService, IAuthSession session, Authenticate request)
        {
            var user = authService.Request.GetUser();
            var userName = user.GetUserName();
            if (!LoginMatchesSession(session, userName))
            {
                authService.RemoveSession();
                session = authService.GetSession();
            }

            if (IsAuthorized(user))
            {
                session.IsAuthenticated = true;
                if (session.UserAuthName == null)
                {
                    session.UserAuthName = userName;
                }

                var aspReq = (HttpRequestBase)authService.Request.OriginalRequest;

                var loginUser = aspReq.ServerVariables["LOGON_USER"].ToNullIfEmpty();
                var remoteUser = aspReq.ServerVariables["REMOTE_USER"].ToNullIfEmpty();
                var identityName = aspReq.LogonUserIdentity != null ? aspReq.LogonUserIdentity.Name : null;
                session.DisplayName = loginUser
                    ?? remoteUser
                    ?? identityName;

                var tokens = new AuthTokens {
                    Provider = Name,
                    UserName = userName,
                    DisplayName = session.DisplayName,
                    Items = new Dictionary<string, string> {
                        {"LOGON_USER", loginUser},
                        {"REMOTE_USER", remoteUser},
                        {"LogonUserIdentityName", identityName},
                    }
                };

                if (session.Roles == null)
                    session.Roles = new List<string>();

                foreach (var role in AllRoles.Safe())
                {
                    if (user.IsInRole(role))
                        session.Roles.AddIfNotExists(role);
                }

                OnAuthenticated(authService, session, tokens, new Dictionary<string, string>());

                return new AuthenticateResponse
                {
                    UserName = userName,
                    SessionId = session.Id,
                    DisplayName = session.DisplayName,
                    ReferrerUrl = request.Continue
                };
            }

            throw HttpError.Unauthorized("Windows Auth failed");
        }
开发者ID:halukmy,项目名称:ServiceStack,代码行数:60,代码来源:AspNetWindowsAuthProvider.cs

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

示例12: TryAuthenticate

        public virtual bool TryAuthenticate(IServiceBase authService, string userName, string password)
        {
            var authRepo = authService.TryResolve<IAuthRepository>();
            if (authRepo == null) {
                Log.WarnFormat("Tried to authenticate without a registered IUserAuthRepository");
                return false;
            }

            var session = authService.GetSession();
            var digestInfo = authService.Request.GetDigestAuth();
            IUserAuth userAuth;
            if (authRepo.TryAuthenticate(digestInfo, PrivateKey, NonceTimeOut, session.Sequence, out userAuth)) {

                var holdSessionId = session.Id;
                session.PopulateWith(userAuth); //overwrites session.Id
                session.Id = holdSessionId;
                session.IsAuthenticated = true;
                session.Sequence = digestInfo["nc"];
                session.UserAuthId = userAuth.Id.ToString(CultureInfo.InvariantCulture);
                session.ProviderOAuthAccess = authRepo.GetUserAuthDetails(session.UserAuthId)
                    .ConvertAll(x => (IAuthTokens) x);

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

示例13: Warning

			public void Warning(IServiceBase @object, string data) {

				if (this.enabled == false) return;

				Debug.LogWarning(string.Format("[ <b>{0}</b> ] {1}", @object.GetServiceName(), data), @object as MonoBehaviour);

			}
开发者ID:Cyberbanan,项目名称:Unity3d.UI.Windows,代码行数:7,代码来源:WindowSystemLogger.cs

示例14: ProcessUserAuthorization

 public virtual IAuthorizationState ProcessUserAuthorization(
     WebServerClient authClient, AuthorizationServerDescription authServer, IServiceBase authService)
 {
     return HostContext.Config.StripApplicationVirtualPath
         ? authClient.ProcessUserAuthorization(authService.Request.ToHttpRequestBase())
         : authClient.ProcessUserAuthorization();
 }
开发者ID:BlakeRaymond-AI,项目名称:ServiceStack,代码行数:7,代码来源:OAuth2Provider.cs

示例15: Authenticate

        protected object Authenticate(IServiceBase authService, IAuthSession session, string userName, string password)
        {
            if (!LoginMatchesSession(session, userName)) {
                authService.RemoveSession();
                session = authService.GetSession();
            }

            if (TryAuthenticate(authService, userName, password))
            {
                session.IsAuthenticated = true;

                if (session.UserAuthName == null) 
                    session.UserAuthName = userName;

                var response = OnAuthenticated(authService, session, null, null);
                if (response != null)
                    return response;

                return new AuthenticateResponse {
                    UserId = session.UserAuthId,
                    UserName = userName,
                    SessionId = session.Id,
                };
            }

            throw HttpError.Unauthorized(ErrorMessages.InvalidUsernameOrPassword);
        }
开发者ID:jango2015,项目名称:ServiceStack,代码行数:27,代码来源:DigestAuthProvider.cs


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