Ejemplo n.º 1
0
        protected void Application_AuthenticateRequest(object sender, EventArgs e)
        {
            try
            {
                IResourceProvider provider = ServiceLocator.Current.GetInstance <IResourceProvider>();
                IResourceContext  context  = new ResourceContextBuilder().FromHttpRequest(new HttpRequestWrapper(HttpContext.Current.Request));
                try
                {
                    provider.AccessProtectedResource(context);
                    TokenPrincipal principal = new TokenPrincipal(new GenericIdentity(context.Token.Token, "OAuth"), context.Token.Scope, context.Token);

                    HttpContext.Current.User = principal;
                }
                catch (OAuthErrorResponseException <IResourceContext> x)
                {
                    Log.Info(m => m("Failed to authorize the token. Error: {0}; Message: {1}", x.Error, x.Message), x);
                    return;
                }
                catch (OAuthFatalException x)
                {
                    StringBuilder report = new StringBuilder();

                    FormatReportHeader(report, "QueryString");
                    FormatReportDictionary(report, context.QueryString);
                    FormatReportHeader(report, "Form");
                    FormatReportDictionary(report, context.Form);
                    FormatReportHeader(report, "Headers");
                    FormatReportDictionary(report, context.Headers);
                    FormatReportHeader(report, "URL");

                    report.AppendLine(HttpContext.Current.Request.Url.ToString());

                    Log.Info(m => m("{0}\r\n{1}", x.Message, report.ToString()), x);
                }
            }
            catch (Exception x)
            {
                Log.Error(x.Message, x);
                throw;
            }
        }
Ejemplo n.º 2
0
        protected void Application_AuthenticateRequest(object sender, EventArgs e)
        {
            try
            {
                IResourceProvider provider = ServiceLocator.Current.GetInstance<IResourceProvider>();
                IResourceContext context = new ResourceContextBuilder().FromHttpRequest(new HttpRequestWrapper(HttpContext.Current.Request));
                try
                {
                    provider.AccessProtectedResource(context);
                    TokenPrincipal principal = new TokenPrincipal(new GenericIdentity(context.Token.Token, "OAuth"), context.Token.Scope, context.Token);

                    HttpContext.Current.User = principal;
                }
                catch (OAuthErrorResponseException<IResourceContext> x)
                {
                    Log.Info(m => m("Failed to authorize the token. Error: {0}; Message: {1}", x.Error, x.Message), x);
                    return;
                }
                catch (OAuthFatalException x)
                {
                    StringBuilder report = new StringBuilder();
                    
                    FormatReportHeader(report, "QueryString");
                    FormatReportDictionary(report, context.QueryString);
                    FormatReportHeader(report, "Form");
                    FormatReportDictionary(report, context.Form);
                    FormatReportHeader(report, "Headers");
                    FormatReportDictionary(report, context.Headers);
                    FormatReportHeader(report, "URL");

                    report.AppendLine(HttpContext.Current.Request.Url.ToString());

                    Log.Info(m => m("{0}\r\n{1}", x.Message, report.ToString()), x);
                }
            }
            catch (Exception x)
            {
                Log.Error(x.Message, x);
                throw;
            }
        }