protected IOAuthTokens Init(IServiceBase authService, ref IAuthSession session, Auth request)
        {
            var requestUri = authService.RequestContext.AbsoluteUri;

            if (this.CallbackUrl.IsNullOrEmpty())
            {
                this.CallbackUrl = requestUri;
            }

            if (session.ReferrerUrl.IsNullOrEmpty())
            {
                session.ReferrerUrl = (request != null ? request.Continue : null) ?? authService.RequestContext.GetHeader("Referer");
            }

            if (session.ReferrerUrl.IsNullOrEmpty() || session.ReferrerUrl.IndexOf("/auth", StringComparison.OrdinalIgnoreCase) >= 0)
            {
                session.ReferrerUrl = this.RedirectUrl
                                      ?? ServiceStackHttpHandlerFactory.GetBaseUrl()
                                      ?? requestUri.Substring(0, requestUri.IndexOf("/", "https://".Length + 1, StringComparison.Ordinal));
            }

            var tokens = session.ProviderOAuthAccess.FirstOrDefault(x => x.Provider == this.Provider);

            if (tokens == null)
            {
                session.ProviderOAuthAccess.Add(tokens = new OAuthTokens {
                    Provider = this.Provider
                });
            }

            return(tokens);
        }
Esempio n. 2
0
        /// <summary>
        /// Overridable method that can be used to implement a custom hnandler
        /// </summary>
        /// <param name="context">The context.</param>
        /// <exception cref="System.NotImplementedException">Cannot execute handler:  + handler +  at PathInfo:  + httpReq.PathInfo</exception>
        protected override void ProcessRequest(HttpListenerContext context)
        {
            if (string.IsNullOrEmpty(context.Request.RawUrl))
            {
                return;
            }

            var operationName = context.Request.GetOperationName();

            var httpReq = new HttpListenerRequestWrapper(operationName, context.Request);
            var httpRes = new HttpListenerResponseWrapper(context.Response);
            var handler = ServiceStackHttpHandlerFactory.GetHandler(httpReq);

            var url      = context.Request.Url.ToString();
            var endPoint = context.Request.RemoteEndPoint;

            var serviceStackHandler = handler as IServiceStackHttpHandler;

            if (serviceStackHandler != null)
            {
                var restHandler = serviceStackHandler as RestHandler;
                if (restHandler != null)
                {
                    httpReq.OperationName = operationName = restHandler.RestPath.RequestType.Name;
                }
                serviceStackHandler.ProcessRequest(httpReq, httpRes, operationName);
                LogResponse(context, url, endPoint);
                httpRes.Close();
                return;
            }

            throw new NotImplementedException("Cannot execute handler: " + handler + " at PathInfo: " + httpReq.PathInfo);
        }
 public void Resolves_the_right_handler_for_expexted_paths()
 {
     foreach (var item in pathInfoMap)
     {
         var expectedType = item.Value;
         var handler      = ServiceStackHttpHandlerFactory.GetHandlerForPathInfo(null, item.Key, null, null);
         Assert.That(handler.GetType(), Is.EqualTo(expectedType));
     }
 }
Esempio n. 4
0
        private static EndpointHandlerBase GetHandler(string httpMethod, string pathInfo)
        {
            var httpHandler = ServiceStackHttpHandlerFactory.GetHandlerForPathInfo(httpMethod, pathInfo, pathInfo, null) as EndpointHandlerBase;

            if (httpHandler == null)
            {
                throw new NotSupportedException(pathInfo);
            }
            return(httpHandler);
        }
Esempio n. 5
0
 public void Resolves_the_right_handler_for_case_insensitive_expexted_paths()
 {
     foreach (var item in pathInfoMap)
     {
         var expectedType  = item.Value;
         var lowerPathInfo = item.Key.ToLower();
         var handler       = ServiceStackHttpHandlerFactory.GetHandlerForPathInfo(null, lowerPathInfo);
         Assert.That(handler.GetType(), Is.EqualTo(expectedType));
     }
 }
Esempio n. 6
0
        public object Get(ResetUserAuth request)
        {
            this.Cache.Remove(SessionFeature.GetSessionKey(Request));

            Db.DeleteAll <UserAuth>();
            Db.DeleteAll <UserOAuthProvider>();

            var referrer = Request.UrlReferrer != null
                ? Request.UrlReferrer.AbsoluteUri
                : ServiceStackHttpHandlerFactory.GetBaseUrl();

            return(HttpResult.Redirect(referrer));
        }
        public static string GetBaseUrl(this IHttpRequest httpReq)
        {
            var baseUrl = ServiceStackHttpHandlerFactory.GetBaseUrl();

            if (baseUrl != null)
            {
                return(baseUrl);
            }

            var handlerPath = EndpointHost.Config.ServiceStackHandlerFactoryPath;

            if (handlerPath != null)
            {
                var pos = httpReq.AbsoluteUri.IndexOf(handlerPath, StringComparison.InvariantCultureIgnoreCase);
                if (pos >= 0)
                {
                    baseUrl = httpReq.AbsoluteUri.Substring(0, pos + handlerPath.Length);
                    return(baseUrl);
                }
                return("/" + handlerPath);
            }

            return("/"); //Can't infer Absolute Uri, fallback to root relative path
        }
        private IHttpHandler GetHandlerForPathParts(string[] pathParts)
        {
            var pathController = string.Intern(pathParts[0].ToLower());

            if (pathParts.Length == 1)
            {
                if (pathController == "metadata")
                {
                    return(new IndexMetadataHandler());
                }

                return(null);
            }

            var pathAction = string.Intern(pathParts[1].ToLower());

            if (pathAction == "wsdl")
            {
                if (pathController == "soap11")
                {
                    return(new Soap11WsdlMetadataHandler());
                }
                if (pathController == "soap12")
                {
                    return(new Soap12WsdlMetadataHandler());
                }
            }

            if (pathAction != "metadata")
            {
                return(null);
            }

            switch (pathController)
            {
            case "json":
                return(new JsonMetadataHandler());

            case "xml":
                return(new XmlMetadataHandler());

            case "jsv":
                return(new JsvMetadataHandler());

            case "soap11":
                return(new Soap11MetadataHandler());

            case "soap12":
                return(new Soap12MetadataHandler());

            case "types":

                if (EndpointHost.AppHost == null ||
                    EndpointHost.AppHost.Config == null ||
                    EndpointHost.AppHost.Config.MetadataTypesConfig == null)
                {
                    return(null);
                }

                if (EndpointHost.AppHost.Config.MetadataTypesConfig.BaseUrl == null)
                {
                    EndpointHost.AppHost.Config.MetadataTypesConfig.BaseUrl = ServiceStackHttpHandlerFactory.GetBaseUrl();
                }

                return(new MetadataTypesHandler {
                    Config = EndpointHost.AppHost.Config.MetadataTypesConfig
                });

            default:
                string contentType;
                if (EndpointHost.ContentTypeFilter
                    .ContentTypeFormats.TryGetValue(pathController, out contentType))
                {
                    var format = Common.Web.ContentType.GetContentFormat(contentType);
                    return(new CustomMetadataHandler(contentType, format));
                }
                break;
            }
            return(null);
        }