Пример #1
0
        public override async Task <bool> InvokeAsync()
        {
            _requestEndpointParameters = new Dictionary <string, string[]>();

            var matchRequestContext = new OAuthMatchEndpointContext(Context, Options, _requestEndpointParameters);

            if (Options.AuthorizeEndpointPath.HasValue && Options.AuthorizeEndpointPath == Request.Path)
            {
                IReadableStringCollection requestParameters = Request.Query;

                foreach (var p in requestParameters)

                {
                    matchRequestContext.QueryString.Add(p.Key, p.Value);
                }

                matchRequestContext.MatchesAuthorizeEndpoint();
            }
            else if (Options.TokenEndpointPath.HasValue && Options.TokenEndpointPath == Request.Path)
            {
                IFormCollection requestParameters = await Request.ReadFormAsync();

                foreach (var p in requestParameters)

                {
                    matchRequestContext.QueryString.Add(p.Key, p.Value);
                }

                matchRequestContext.MatchesTokenEndpoint();
            }
            await Options.Provider.MatchEndpoint(matchRequestContext);

            if (matchRequestContext.IsRequestCompleted)
            {
                return(true);
            }

            if (matchRequestContext.IsAuthorizeEndpoint || matchRequestContext.IsTokenEndpoint)
            {
                if (!Options.AllowInsecureHttp &&
                    String.Equals(Request.Scheme, Uri.UriSchemeHttp, StringComparison.OrdinalIgnoreCase))
                {
                    _logger.WriteWarning("Authorization server ignoring http request because AllowInsecureHttp is false.");
                    return(false);
                }
                if (matchRequestContext.IsAuthorizeEndpoint)
                {
                    return(await InvokeAuthorizeEndpointAsync());
                }
                if (matchRequestContext.IsTokenEndpoint)
                {
                    await InvokeTokenEndpointAsync();

                    return(true);
                }
            }
            return(false);
        }
        public override async Task <bool> InvokeAsync()
        {
            var matchRequestContext = new OAuthMatchEndpointContext(Context, Options);

            if (Options.AuthorizeEndpointPath.HasValue && Options.AuthorizeEndpointPath == Request.Path)
            {
                matchRequestContext.MatchesAuthorizeEndpoint();
            }
            else if (Options.TokenEndpointPath.HasValue && Options.TokenEndpointPath == Request.Path)
            {
                matchRequestContext.MatchesTokenEndpoint();
            }
            await Options.Provider.MatchEndpoint(matchRequestContext);

            if (matchRequestContext.IsRequestCompleted)
            {
                return(true);
            }

            if (matchRequestContext.IsAuthorizeEndpoint || matchRequestContext.IsTokenEndpoint)
            {
                if (!Options.AllowInsecureHttp &&
                    String.Equals(Request.Scheme, Uri.UriSchemeHttp, StringComparison.OrdinalIgnoreCase))
                {
                    _logger.WriteWarning("Authorization server ignoring http request because AllowInsecureHttp is false.");
                    return(false);
                }
                if (matchRequestContext.IsAuthorizeEndpoint)
                {
                    return(await InvokeAuthorizeEndpointAsync());
                }
                if (matchRequestContext.IsTokenEndpoint)
                {
                    await InvokeTokenEndpointAsync();

                    return(true);
                }
            }
            return(false);
        }