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


C# IRequest.TryResolve方法代码示例

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


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

示例1: Execute

        public override void Execute(IRequest req, IResponse res, object requestDto)
        {
            if (req.IsLocal)
                return;

            var appConfig = req.TryResolve<AppConfig>();
            var apiKey = req.Headers["x-api-key"] ?? req.QueryString["api_key"];

            if (apiKey == null || !appConfig.ReadWriteApiKeys.Contains(apiKey))
            {
                throw HttpError.Unauthorized("Unauthorized.  Valid x-api-key header required.");
            }
        }
开发者ID:jrmitch120,项目名称:CrawlLeague,代码行数:13,代码来源:ApiKeyAttribute.cs

示例2: PreAuthenticate

        public void PreAuthenticate(IRequest req, IResponse res)
        {
            //Need to run SessionFeature filter since its not executed before this attribute (Priority -100)			
            SessionFeature.AddSessionIdToRequestFilter(req, res, null); //Required to get req.GetSessionId()

            var userPass = req.GetBasicAuthUserAndPassword();
            if (userPass != null)
            {
                var authService = req.TryResolve<AuthenticateService>();
                authService.Request = req;
                var response = authService.Post(new Authenticate
                {
                    provider = Name,
                    UserName = userPass.Value.Key,
                    Password = userPass.Value.Value
                });
            }
        }
开发者ID:vebin,项目名称:soa,代码行数:18,代码来源:BasicAuthProvider.cs

示例3: HasAllPermissions

        public bool HasAllPermissions(IRequest req, IAuthSession session, IAuthRepository userAuthRepo=null)
        {
            if (HasAllPermissions(session)) return true;

            if (userAuthRepo == null) 
                userAuthRepo = req.TryResolve<IAuthRepository>();

            if (userAuthRepo == null) return false;

            var userAuth = userAuthRepo.GetUserAuth(session, null);
            session.UpdateSession(userAuth);

            if (HasAllPermissions(session))
            {
                req.SaveSession(session);
                return true;
            }
            return false;
        }
开发者ID:nustack,项目名称:ServiceStack,代码行数:19,代码来源:RequiredPermissionAttribute.cs

示例4: AssertRequiredRoles

        /// <summary>
        /// Check all session is in any supplied roles otherwise a 401 HttpError is thrown
        /// </summary>
        /// <param name="request"></param>
        /// <param name="requiredRoles"></param>
        public static void AssertRequiredRoles(IRequest request, params string[] requiredRoles)
        {
            if (requiredRoles.IsEmpty()) return;

            var req = request.TryResolve<IHttpRequest>();
            if (HostContext.HasValidAuthSecret(req))
                return;

            var session = req.GetSession();

            if (session != null && session.UserAuthId != null && requiredRoles.Any(session.HasRole))
                return;

            session.UpdateFromUserAuthRepo(req);

            if (session != null && session.UserAuthId != null && requiredRoles.Any(session.HasRole))
                return;

            var statusCode = session != null && session.IsAuthenticated
                ? (int)HttpStatusCode.Forbidden
                : (int)HttpStatusCode.Unauthorized;

            throw new HttpError(statusCode, "Invalid Role");
        }
开发者ID:nunopimenta,项目名称:ServiceStack,代码行数:29,代码来源:RequiresAnyRoleAttribute.cs

示例5: PreAuthenticate

        public void PreAuthenticate(IRequest req, IResponse res)
        {
            //Need to run SessionFeature filter since its not executed before this attribute (Priority -100)			
            SessionFeature.AddSessionIdToRequestFilter(req, res, null); //Required to get req.GetSessionId()

            var digestAuth = req.GetDigestAuth();
            if (digestAuth != null)
            {
                var authService = req.TryResolve<AuthenticateService>();
                authService.Request = req;
                var response = authService.Post(new Authenticate
                {
                    provider = Name,
                    nonce = digestAuth["nonce"],
                    uri = digestAuth["uri"],
                    response = digestAuth["response"],
                    qop = digestAuth["qop"],
                    nc = digestAuth["nc"],
                    cnonce = digestAuth["cnonce"],
                    UserName = digestAuth["username"]
                });
            }
        }
开发者ID:jango2015,项目名称:ServiceStack,代码行数:23,代码来源:DigestAuthProvider.cs

示例6: PreAuthenticate

        public void PreAuthenticate(IRequest request, IResponse response)
        {
            var header = request.Headers["Authorization"];
            var authService = request.TryResolve<AuthenticateService>();
            authService.Request = request;

            // pass auth header in as oauth token to authentication
            authService.Post(new Authenticate
            {
                provider = Name,
                oauth_token = header
            });
        }
开发者ID:Estyn,项目名称:ServiceStackJWT,代码行数:13,代码来源:JsonWebTokenAuthProvider.cs

示例7: GetPageName

 public string GetPageName(object dto, IRequest requestContext)
 {
     var httpRequest = requestContext != null ? requestContext.TryResolve<IHttpRequest>() : null;
     var httpResult = dto as IHttpResult;
     if (httpResult != null)
     {
         dto = httpResult.Response;
     }
     if (dto != null) return dto.GetType().Name;
     return httpRequest != null ? httpRequest.OperationName : null;
 }
开发者ID:0815sugo,项目名称:ServiceStack,代码行数:11,代码来源:MarkdownFormat.cs

示例8: PreAuthenticate

        public void PreAuthenticate(IRequest req, IResponse res)
        {
            SessionFeature.AddSessionIdToRequestFilter(req, res, null); //Required to get req.GetSessionId()

            var authService = req.TryResolve<AuthenticateService>();
            authService.Request = req;
            var user = req.GetUser();

            if (user != null)
            {
                var session = req.GetSession();
                if (LoginMatchesSession(session, user.Identity.Name)) return;

                var response = authService.Post(new Authenticate
                {
                    provider = Name,
                    UserName = user.GetUserName(),
                });
            }
        }
开发者ID:vebin,项目名称:soa,代码行数:20,代码来源:AspNetWindowsAuthProvider.cs

示例9: ProcessRequestAsync

            public override Task ProcessRequestAsync(IRequest req, IResponse res, string operationName)
            {
                res.ContentType = MimeTypes.ServerSentEvents;
                res.AddHeader(HttpHeaders.CacheControl, "no-cache");
                res.KeepAlive = true;
                res.Flush();

                IAuthSession session = req.GetSession();
                var userAuthId = session != null ? session.UserAuthId : null;
                var feature = HostContext.GetPlugin<SimpleServerEventsFeature>();

                //var now = DateTime.UtcNow;
                var subscriptionId = SessionExtensions.CreateRandomSessionId();
                var eventClient = new EventClient(res)
                {
                    SubscriptionId = subscriptionId,     // A session can have multiple subscriptions / clients
                };

                if (feature.OnCreated != null)
                    feature.OnCreated(eventClient, req);

                //var heartbeatUrl = req.ResolveAbsoluteUrl("~/".CombineWith(feature.HeartbeatPath))
                //    .AddQueryParam("id", subscriptionId);

                var privateArgs = new Dictionary<string, string>(eventClient.Meta) {
                        {"id", subscriptionId },
                        //{"heartbeatUrl", heartbeatUrl},
                        //{"heartbeatIntervalMs", ((long)feature.HeartbeatInterval.TotalMilliseconds).ToString(CultureInfo.InvariantCulture) }
                };

                // Register the client
                req.TryResolve<IServerEventsBroker>().Connect(eventClient);

                if (feature.OnConnected != null)
                    feature.OnConnected(eventClient, privateArgs);

                // Welcome our new client
                res.OutputStream.Write(": " + subscriptionId + " connected\n\n");     // Write initial stream so the client knows we're alive
                res.Flush();
                var tcs = new TaskCompletionSource<bool>();

                eventClient.OnDispose = client =>
                {
                    try
                    {
                        res.EndHttpHandlerRequest(skipHeaders: true);
                    }
                    catch { }
                    tcs.SetResult(true);
                };

                return tcs.Task;
            }
开发者ID:jklemmack,项目名称:ServerSentEvents4ServiceStack,代码行数:53,代码来源:SimpleServerEventsFeature.cs

示例10: PreAuthenticate

        public void PreAuthenticate(IRequest req, IResponse res)
        {
            //Need to run SessionFeature filter since its not executed before this attribute (Priority -100)
            SessionFeature.AddSessionIdToRequestFilter(req, res, null); //Required to get req.GetSessionId()

            var httpRequestBase = req.ToHttpRequestBase();
            var bearerToken = httpRequestBase.QueryString["access_token"] ?? "bearer-token-value";
            //var unityStsProxyService = new UnityStsProxyService();// req.TryResolve<UnityStsProxyService>();
            var unityStsProxyService = req.TryResolve<UnityStsProxyService>();
            unityStsProxyService.Request = req;
            req.SetSessionId(bearerToken);
            var session = req.GetSession();
            if (!session.IsAuthenticated)
            {
                unityStsProxyService.Any(new GetTokenInfo { BearerToken = bearerToken });
            }
        }
开发者ID:cri-at-work,项目名称:SS-AuthProvider,代码行数:17,代码来源:UnityServiceAuthProvider.cs

示例11: OnRegistered

 public override void OnRegistered(IRequest httpReq, IAuthSession session, IServiceBase registrationService)
 {
     var apiKeys = apiKeyProvider.GenerateNewApiKeys(session.UserAuthId);
     var authRepo = (IManageApiKeys)httpReq.TryResolve<IAuthRepository>().AsUserAuthRepository(httpReq);
     authRepo.StoreAll(apiKeys);
 }
开发者ID:migajek,项目名称:ServiceStack,代码行数:6,代码来源:ApiKeyAuthProvider.cs

示例12: PreAuthenticateWithApiKey

        private static void PreAuthenticateWithApiKey(IRequest req, IResponse res, string apiKey)
        {
            //Need to run SessionFeature filter since its not executed before this attribute (Priority -100)			
            SessionFeature.AddSessionIdToRequestFilter(req, res, null); //Required to get req.GetSessionId()

            using (var authService = req.TryResolve<AuthenticateService>())
            {
                authService.Request = req;
                var response = authService.Post(new Authenticate
                {
                    provider = Name,
                    UserName = "ApiKey",
                    Password = apiKey,
                });
            }
        }
开发者ID:migajek,项目名称:ServiceStack,代码行数:16,代码来源:ApiKeyAuthProvider.cs

示例13: PreAuthenticate

        public void PreAuthenticate(IRequest req, IResponse res)
        {
            //The API Key is sent in the Basic Auth Username and Password is Empty
            var userPass = req.GetBasicAuthUserAndPassword();
            if (userPass != null && string.IsNullOrEmpty(userPass.Value.Value))
            {
                if (RequireSecureConnection && !req.IsSecureConnection)
                    throw HttpError.Forbidden(ErrorMessages.ApiKeyRequiresSecureConnection);

                var apiKey = userPass.Value.Key;

                PreAuthenticateWithApiKey(req, res, apiKey);
            }
            var bearerToken = req.GetBearerToken();
            if (bearerToken != null)
            {
                var authRepo = (IManageApiKeys)req.TryResolve<IAuthRepository>().AsUserAuthRepository(req);
                if (authRepo.ApiKeyExists(bearerToken))
                {
                    if (RequireSecureConnection && !req.IsSecureConnection)
                        throw HttpError.Forbidden(ErrorMessages.ApiKeyRequiresSecureConnection);

                    PreAuthenticateWithApiKey(req, res, bearerToken);
                }
            }
        }
开发者ID:migajek,项目名称:ServiceStack,代码行数:26,代码来源:ApiKeyAuthProvider.cs

示例14: OnRegistered

        public override void OnRegistered(IRequest httpReq, IAuthSession session, IServiceBase registrationService)
        {
            var now = DateTime.UtcNow;
            var userId = session.UserAuthId;
            var apiKeys = new List<ApiKey>();

            foreach (var env in apiKeyProvider.Environments)
            {
                foreach (var keyType in apiKeyProvider.KeyTypes)
                {
                    var key = apiKeyProvider.CreateApiKeyFn(env, keyType, apiKeyProvider.KeySizeBytes);

                    var apiKey = new ApiKey
                    {
                        UserAuthId = userId,
                        Environment = env,
                        KeyType = keyType,
                        Id = key,
                        CreatedDate = now,
                    };

                    if (apiKeyProvider.ApiKeyFilterFn != null)
                        apiKeyProvider.ApiKeyFilterFn(apiKey);

                    apiKeys.Add(apiKey);
                }
            }

            var authRepo = (IManageApiKeys)httpReq.TryResolve<IAuthRepository>().AsUserAuthRepository(httpReq);
            authRepo.StoreAll(apiKeys);
        }
开发者ID:jeremymeng,项目名称:ServiceStack,代码行数:31,代码来源:ApiKeyAuthProvider.cs


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