Ejemplo n.º 1
0
        /// <summary>Initialises this object.</summary>
        ///
        /// <param name="authService">The authentication service.</param>
        /// <param name="session">    The session.</param>
        /// <param name="request">    The request.</param>
        ///
        /// <returns>The IOAuthTokens.</returns>
        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
                                      ?? NServiceKitHttpHandlerFactory.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);
        }
Ejemplo n.º 2
0
        /// <summary>Gets the given request.</summary>
        ///
        /// <param name="request">The request to get.</param>
        ///
        /// <returns>An object.</returns>
        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
                : NServiceKitHttpHandlerFactory.GetBaseUrl();

            return(HttpResult.Redirect(referrer));
        }
        /// <summary>An IHttpRequest extension method that gets base URL.</summary>
        ///
        /// <param name="httpReq">The httpReq to act on.</param>
        ///
        /// <returns>The base URL.</returns>
        public static string GetBaseUrl(this IHttpRequest httpReq)
        {
            var baseUrl = NServiceKitHttpHandlerFactory.GetBaseUrl();

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

            var handlerPath = EndpointHost.Config.NServiceKitHandlerFactoryPath;

            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
        }
Ejemplo n.º 4
0
        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.Config == null ||
                    EndpointHost.Config.MetadataTypesConfig == null)
                {
                    return(null);
                }

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

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

            case "operations":

                return(new ActionHandler((httpReq, httpRes) =>
                                         EndpointHost.Config.HasAccessToMetadata(httpReq, httpRes)
                            ? EndpointHost.Metadata.GetOperationDtos()
                            : null, "Operations"));

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